## 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 empty_result_callbacks = YES;
PRAGMA legacy_alter_table = 0;
ATTACH DATABASE ':memory:' AS aux1;
ATTACH DATABASE ':memory:' AS aux98;
BEGIN IMMEDIATE;
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c INT, d INT);
INSERT INTO t1 VALUES (round(CAST(2147483646 AS INT8)), 'Wernher', 10, 100);
INSERT INTO t1 VALUES (2, 'von', 20, 200);
INSERT INTO t1 VALUES (3, 'Braun', 30, 300);

CREATE INDEX t1bc ON t1(b, c);

PRAGMA writable_schema = ON;

.imposter t1bc t2

SELECT * FROM t2;

SELECT b, c FROM t1 ORDER BY b, c;

.quit
.progress 3
.echo
ATTACH DATABASE ':memory:' AS aux59;
ATTACH DATABASE ':memory:' AS aux82;
BEGIN IMMEDIATE TRANSACTION;
CREATE TABLE T (
  A VARCHAR(10) PRIMARY KEY,
  B VARCHAR(15),
  C BIGINT NOT NULL,
  UNIQUE (B, C)
);
INSERT INTO T VALUES ('a', 'p', 3000);
INSERT INTO T VALUES ('b', 'q', 9223372036854775807);
INSERT INTO T VALUES ('c', 'r', 1700);
INSERT INTO T VALUES ('e', 'q', -9223372036854775808);
INSERT INTO T VALUES ('f', 'r', 0);
SELECT B, COUNT(*) AS D, SUM(C) AS E, AVG(C) AS F FROM T GROUP BY B HAVING SUM(C) > 0;
DELETE FROM T WHERE 0 RETURNING *;
COMMIT TRANSACTION;
SELECT LAG(C, 0) OVER (ORDER BY C ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW EXCLUDE TIES) FROM T;
CREATE  INDEX IF NOT EXISTS idx_T_770 ON T((C + 1)) WHERE +C > 0;
SELECT AVG(A) OVER (ORDER BY A ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE GROUP) FROM T;
SELECT * FROM T WHERE C > (SELECT COUNT(*) FROM T);
DETACH DATABASE aux82;
SELECT NTH_VALUE(A, 2) OVER (ORDER BY A ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM T;
DETACH DATABASE aux59;
INSERT OR ROLLBACK INTO T VALUES (NULL, 0, -8);
INSERT INTO T SELECT * FROM T;
INSERT INTO T SELECT * FROM T;
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c INT, d INT);
INSERT INTO t1 VALUES (1, 'Wernher', 10, 100);
INSERT INTO t1 VALUES (2, 'von', 20, 200);
INSERT INTO t1 VALUES (3, 'Braun', 30, 300);

CREATE INDEX t1bc ON t1(b, c);

PRAGMA writable_schema = ON;

.imposter t1bc t2

SELECT * FROM t2;

SELECT b, c FROM t1 ORDER BY b, c;

.quit
.progress 3
.echo
ATTACH DATABASE ':memory:' AS aux59;
ATTACH DATABASE ':memory:' AS aux82;
BEGIN IMMEDIATE TRANSACTION;
CREATE TABLE T (
  A VARCHAR(10) PRIMARY KEY,
  B VARCHAR(15),
  C BIGINT NOT NULL,
  UNIQUE (B, C)
);
INSERT INTO T VALUES ('a', 'p', 3000);
INSERT INTO T VALUES ('b', 'q', 9223372036854775807);
INSERT INTO T VALUES ('c', 'r', 1700);
INSERT INTO T VALUES ('e', 'q', -9223372036854775808);
INSERT INTO T VALUES ('f', 'r', 0);
SELECT B, COUNT(*) AS D, SUM(C) AS E, AVG(C) AS F FROM T GROUP BY B HAVING SUM(C) > 0;
DELETE FROM T WHERE 0 RETURNING *;
COMMIT TRANSACTION;
SELECT LAG(C, 0) OVER (ORDER BY C ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW EXCLUDE TIES) FROM T;
CREATE  INDEX IF NOT EXISTS idx_T_770 ON T((C + 1)) WHERE +C > 0;
SELECT AVG(A) OVER (ORDER BY A ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE GROUP) FROM T;
SELECT * FROM T WHERE C > (SELECT COUNT(*) FROM T);
DETACH DATABASE aux82;
SELECT NTH_VALUE(A, 2) OVER (ORDER BY A ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM T;
DETACH DATABASE aux59;
INSERT OR ROLLBACK INTO T VALUES (NULL, 0, -8);
INSERT INTO T SELECT * FROM T;
INSERT INTO T SELECT * FROM T;
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c INT, d INT);
INSERT INTO t1 VALUES (1, 'Wernher', 10, 100);
INSERT INTO t1 VALUES (2, 'von', 20, 200);
INSERT INTO t1 VALUES (3, 'Braun', 30, 300);

CREATE INDEX t1bc ON t1(b, c);

PRAGMA writable_schema = ON;

.imposter t1bc t2

SELECT * FROM t2;

SELECT b, c FROM t1 ORDER BY b, c;

.quit
.progress 3
.echo
ATTACH DATABASE ':memory:' AS aux59;
ATTACH DATABASE ':memory:' AS aux82;
BEGIN IMMEDIATE TRANSACTION;
CREATE TABLE T (
  A VARCHAR(10) PRIMARY KEY,
  B VARCHAR(15),
  C BIGINT NOT NULL,
  UNIQUE (B, C)
);
INSERT INTO T VALUES ('a', 'p', 3000);
INSERT INTO T VALUES ('b', 'q', 9223372036854775807);
INSERT INTO T VALUES ('c', 'r', 1700);
INSERT INTO T VALUES ('e', 'q', -9223372036854775808);
INSERT INTO T VALUES ('f', 'r', 0);
SELECT B, COUNT(*) AS D, SUM(C) AS E, AVG(C) AS F FROM T GROUP BY B HAVING SUM(C) > 0;
DELETE FROM T WHERE 0 RETURNING *;
COMMIT TRANSACTION;
SELECT LAG(C, 0) OVER (ORDER BY C ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW EXCLUDE TIES) FROM T;
CREATE  INDEX IF NOT EXISTS idx_T_770 ON T((C + 1)) WHERE +C > 0;
SELECT AVG(A) OVER (ORDER BY A ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE GROUP) FROM T;
SELECT * FROM T WHERE C > (SELECT COUNT(*) FROM T);
DETACH DATABASE aux82;
SELECT NTH_VALUE(A, 2) OVER (ORDER BY A ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM T;
DETACH DATABASE aux59;
INSERT OR ROLLBACK INTO T VALUES (NULL, 0, -8);
INSERT INTO T SELECT * FROM T;
INSERT INTO T SELECT * FROM T;
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c INT, d INT);
INSERT INTO t1 VALUES (1, 'Wernher', 10, 100);
INSERT INTO t1 VALUES (2, 'von', 20, 200);
INSERT INTO t1 VALUES (3, 'Braun', 30, 300);

CREATE INDEX t1bc ON t1(b, c);

PRAGMA writable_schema = ON;

.imposter t1bc t2

SELECT * FROM t2;

SELECT b, c FROM t1 ORDER BY b, c;

.quit
.progress 3
.echo
ATTACH DATABASE ':memory:' AS aux59;
ATTACH DATABASE ':memory:' AS aux82;
BEGIN IMMEDIATE TRANSACTION;
CREATE TABLE T (
  A VARCHAR(10) PRIMARY KEY,
  B VARCHAR(15),
  C BIGINT NOT NULL,
  UNIQUE (B, C)
);
INSERT INTO T VALUES ('a', 'p', 3000);
INSERT INTO T VALUES ('b', 'q', 9223372036854775807);
INSERT INTO T VALUES ('c', 'r', 1700);
INSERT INTO T VALUES ('e', 'q', -9223372036854775808);
INSERT INTO T VALUES ('f', 'r', 0);
SELECT B, COUNT(*) AS D, SUM(C) AS E, AVG(C) AS F FROM T GROUP BY B HAVING SUM(C) > 0;
DELETE FROM T WHERE 0 RETURNING *;
COMMIT TRANSACTION;
SELECT LAG(C, 0) OVER (ORDER BY C ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW EXCLUDE TIES) FROM T;
CREATE  INDEX IF NOT EXISTS idx_T_770 ON T((C + 1)) WHERE +C > 0;
SELECT AVG(A) OVER (ORDER BY A ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE GROUP) FROM T;
SELECT * FROM T WHERE C > (SELECT COUNT(*) FROM T);
DETACH DATABASE aux82;
SELECT NTH_VALUE(A, 2) OVER (ORDER BY A ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM T;
DETACH DATABASE aux59;
INSERT OR ROLLBACK INTO T VALUES (NULL, 0, -8);
INSERT INTO T SELECT * FROM T;
INSERT INTO T SELECT * FROM T;
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c INT, d INT);
INSERT INTO t1 VALUES (1, 'Wernher', 10, 100);
INSERT INTO t1 VALUES (2, 'von', 20, 200);
INSERT INTO t1 VALUES (3, 'Braun', 30, 300);

CREATE INDEX t1bc ON t1(b, c);

PRAGMA writable_schema = ON;

.imposter t1bc t2

SELECT * FROM t2;

SELECT b, c FROM t1 ORDER BY b, c;

.quit
.progress 3
.echo
ATTACH DATABASE ':memory:' AS aux59;
ATTACH DATABASE ':memory:' AS aux82;
BEGIN IMMEDIATE TRANSACTION;
CREATE TABLE T (
  A VARCHAR(10) PRIMARY KEY,
  B VARCHAR(15),
  C BIGINT NOT NULL,
  UNIQUE (B, C)
);
INSERT INTO T VALUES ('a', 'p', 3000);
INSERT INTO T VALUES ('b', 'q', 9223372036854775807);
INSERT INTO T VALUES ('c', 'r', 1700);
INSERT INTO T VALUES ('e', 'q', -9223372036854775808);
INSERT INTO T VALUES ('f', 'r', 0);
SELECT B, COUNT(*) AS D, SUM(C) AS E, AVG(C) AS F FROM T GROUP BY B HAVING SUM(C) > 0;
DELETE FROM T WHERE 0 RETURNING *;
COMMIT TRANSACTION;
SELECT LAG(C, 0) OVER (ORDER BY C ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW EXCLUDE TIES) FROM T;
CREATE  INDEX IF NOT EXISTS idx_T_770 ON T((C + 1)) WHERE +C > 0;
SELECT AVG(A) OVER (ORDER BY A ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE GROUP) FROM T;
SELECT * FROM T WHERE C > (SELECT COUNT(*) FROM T);
DETACH DATABASE aux82;
SELECT NTH_VALUE(A, 2) OVER (ORDER BY A ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM T;
DETACH DATABASE aux59;
INSERT OR ROLLBACK INTO T VALUES (NULL, 0, -8);
INSERT INTO T SELECT * FROM T;
INSERT INTO T SELECT * FROM T;
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c INT, d INT);
INSERT INTO t1 VALUES (1, 'Wernher', 10, 100);
INSERT INTO t1 VALUES (2, 'von', 20, 200);
INSERT INTO t1 VALUES (3, 'Braun', 30, 300);

CREATE INDEX t1bc ON t1(b, c);

PRAGMA writable_schema = ON;

.imposter t1bc t2

SELECT * FROM t2;

SELECT b, c FROM t1 ORDER BY b, c;

.quit
.progress 3
.echo
ATTACH DATABASE ':memory:' AS aux59;
ATTACH DATABASE ':memory:' AS aux82;
BEGIN IMMEDIATE TRANSACTION;
CREATE TABLE T (
  A VARCHAR(10) PRIMARY KEY,
  B VARCHAR(15),
  C BIGINT NOT NULL,
  UNIQUE (B, C)
);
INSERT INTO T VALUES ('a', 'p', 3000);
INSERT INTO T VALUES ('b', 'q', 9223372036854775807);
INSERT INTO T VALUES ('c', 'r', 1700);
INSERT INTO T VALUES ('e', 'q', -9223372036854775808);
INSERT INTO T VALUES ('f', 'r', 0);
SELECT B, COUNT(*) AS D, SUM(C) AS E, AVG(C) AS F FROM T GROUP BY B HAVING SUM(C) > 0;
DELETE FROM T WHERE 0 RETURNING *;
COMMIT TRANSACTION;
SELECT LAG(C, 0) OVER (ORDER BY C ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW EXCLUDE TIES) FROM T;
CREATE  INDEX IF NOT EXISTS idx_T_770 ON T((C + 1)) WHERE +C > 0;
SELECT AVG(A) OVER (ORDER BY A ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE GROUP) FROM T;
SELECT * FROM T WHERE C > (SELECT COUNT(*) FROM T);
DETACH DATABASE aux82;
SELECT NTH_VALUE(A, 2) OVER (ORDER BY A ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM T;
DETACH DATABASE aux59;
INSERT OR ROLLBACK INTO T VALUES (NULL, 0, -8);
INSERT INTO T SELECT * FROM T;
INSERT INTO T SELECT * FROM T;
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c INT, d INT);
INSERT INTO t1 VALUES (1, 'Wernher', 10, 100);
INSERT INTO t1 VALUES (2, 'von', 20, 200);
INSERT INTO t1 VALUES (3, 'Braun', 30, 300);

CREATE INDEX t1bc ON t1(b, c);

PRAGMA writable_schema = ON;

.imposter t1bc t2

SELECT * FROM t2;

SELECT b, c FROM t1 ORDER BY b, c;

.quit
.progress 3
.echo
ATTACH DATABASE ':memory:' AS aux59;
ATTACH DATABASE ':memory:' AS aux82;
BEGIN IMMEDIATE TRANSACTION;
CREATE TABLE T (
  A VARCHAR(10) PRIMARY KEY,
  B VARCHAR(15),
  C BIGINT NOT NULL,
  UNIQUE (B, C)
);
INSERT INTO T VALUES ('a', 'p', 3000);
INSERT INTO T VALUES ('b', 'q', 9223372036854775807);
INSERT INTO T VALUES ('c', 'r', 1700);
INSERT INTO T VALUES ('e', 'q', -9223372036854775808);
INSERT INTO T VALUES ('f', 'r', 0);
SELECT B, COUNT(*) AS D, SUM(C) AS E, AVG(C) AS F FROM T GROUP BY B HAVING SUM(C) > 0;
DELETE FROM T WHERE 0 RETURNING *;
COMMIT TRANSACTION;
SELECT LAG(C, 0) OVER (ORDER BY C ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW EXCLUDE TIES) FROM T;
CREATE  INDEX IF NOT EXISTS idx_T_770 ON T((C + 1)) WHERE +C > 0;
SELECT AVG(A) OVER (ORDER BY A ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE GROUP) FROM T;
SELECT * FROM T WHERE C > (SELECT COUNT(*) FROM T);
DETACH DATABASE aux82;
SELECT NTH_VALUE(A, 2) OVER (ORDER BY A ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM T;
DETACH DATABASE aux59;
INSERT OR ROLLBACK INTO T VALUES (NULL, 0, -8);
INSERT INTO T SELECT * FROM T;
INSERT INTO T SELECT * FROM T;
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c INT, d INT);
INSERT INTO t1 VALUES (1, 'Wernher', 10, 100);
INSERT INTO t1 VALUES (2, 'von', 20, 200);
INSERT INTO t1 VALUES (3, 'Braun', 30, 300);

CREATE INDEX t1bc ON t1(b, c);

PRAGMA writable_schema = ON;

.imposter t1bc t2

SELECT * FROM t2;

SELECT b, c FROM t1 ORDER BY b, c;

.quit
.progress 3
.echo
ATTACH DATABASE ':memory:' AS aux59;
ATTACH DATABASE ':memory:' AS aux82;
BEGIN IMMEDIATE TRANSACTION;
CREATE TABLE T (
  A VARCHAR(10) PRIMARY KEY,
  B VARCHAR(15),
  C BIGINT NOT NULL,
  UNIQUE (B, C)
);
INSERT INTO T VALUES ('a', 'p', 3000);
INSERT INTO T VALUES ('b', 'q', 9223372036854775807);
INSERT INTO T VALUES ('c', 'r', 1700);
INSERT INTO T VALUES ('e', 'q', -9223372036854775808);
INSERT INTO T VALUES ('f', 'r', 0);
SELECT B, COUNT(*) AS D, SUM(C) AS E, AVG(C) AS F FROM T GROUP BY B HAVING SUM(C) > 0;
DELETE FROM T WHERE 0 RETURNING *;
COMMIT TRANSACTION;
SELECT LAG(C, 0) OVER (ORDER BY C ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW EXCLUDE TIES) FROM T;
CREATE  INDEX IF NOT EXISTS idx_T_770 ON T((C + 1)) WHERE +C > 0;
SELECT AVG(A) OVER (ORDER BY A ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE GROUP) FROM T;
SELECT * FROM T WHERE C > (SELECT COUNT(*) FROM T);
DETACH DATABASE aux82;
SELECT NTH_VALUE(A, 2) OVER (ORDER BY A ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM T;
DETACH DATABASE aux59;
INSERT OR ROLLBACK INTO T VALUES (NULL, 0, -8);
INSERT INTO T SELECT * FROM T;
INSERT INTO T SELECT * FROM T;


SELECT COUNT(*) FROM T;
UPdatE T SET B = '' WHERE rowid = 1 RETURNING *;
SELECT COUNT(*) FILTER (WHERE a IS NOT NULL), SUM(rowid) FILTER (WHERE a > 0), COUNT(*) FILTER (WHERE 1=0), COUNT(*) FILTER (WHERE 1=1), COUNT(*) FILTER (WHERE NULL), AVG(a) FILTER (WHERE a > 0 AND a < 100), COUNT(*) FILTER (WHERE typeof(a) = "text") FROM t1;
END TRANSACTION;
CREATE TRIGGER IF NOT EXISTS trg_t1_4619 AFTER UPDATE ON t1 FOR EACH ROW BEGIN SELECT RAISE(ROLLBACK, 'rb'); END;
SELECT * FROM t1 AS a JOIN t1 AS b ON a.rowid = b.rowid;
SELECT * FROM T WHERE C IN (SELECT C FROM T WHERE C GLOB "*");
SELECT * FROM t1 AS a FULL JOIN T AS b ON a.rowid = b.rowid;
SELECT * FROM (SELECT * FROM (SELECT * FROM t1) AS inner1) AS inner2;
DETACH DATABASE aux98;
CREATE  VIEW IF NOT EXISTS v_T_6251 AS SELECT A FROM T;
WITH cte AS (SELECT * FROM T) SELECT * FROM cte;
CREATE  INDEX IF NOT EXISTS idx_T_4166 ON T(A);
SELECT * FROM t1 t1 JOIN (SELECT * FROM t1) AS sub ON t1.b = sub.b;
DETACH DATABASE aux1;
SELECT * FROM T NATURAL JOIN T;
ALTER TABLE T RENAME COLUMN A TO A_r1687;
SELECT LAG(d, 1, NULL) OVER (PARTITION BY d ORDER BY d RANGE BETWEEN 1 PRECEDING AND 1 FOLLOWING) FROM t1;
ALTER TABLE t1 DROP COLUMN c;
INSERT INTO T DEFAULT VALUES;
SELECT * FROM T;
PRAGMA synchronous = 'NORMAL';
WITH a AS NOT MATERIALIZED (SELECT * FROM t1), b AS MATERIALIZED (SELECT * FROM a) SELECT * FROM b;
ALTER TABLE t1 RENAME COLUMN c TO c_r9513;

```

## Actual output

```sql
CREATE TABLE "t2"("b","c","_ROWID_",PRIMARY KEY("b","c","_ROWID_"))WITHOUT ROWID;
WARNING: writing to an imposter table will corrupt the "t1bc" index!
Braun|30|3
Wernher|10|2147483646
von|20|2
Braun|30
Wernher|10
von|20
```

## Expectation

```sql
CREATE TABLE "t2"("b","c","_ROWID_",PRIMARY KEY("b","c","_ROWID_"))WITHOUT ROWID;
Braun|30|3
Wernher|10|2147483646
von|20|2
Braun|30
Wernher|10
von|20
```

## Flag

```

```

