## 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 t1(a INTEGER PRIMARY KEY, b TEXT, c INT, d INT);
INSERT INTO t1 VALUES (CAST(1 AS DATETIME), '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
ATTACH DATABASE ':memory:' AS aux43;
PRAGMA case_sensitive_like = ON;
ATTACH DATABASE ':memory:' AS aux87;
PRAGMA writable_schema = OFF;
-- -vfs unix-none

.open corrupt001.db
SAVEPOINT sp6286;
PRAGMA read_uncommitted;
.open
ATTACH DATABASE ':memory:' AS aux67;
.print
BEGIN DEFERRED;
-- jsonb_extract({v}, '$.key')

ATTACH DATABASE ':memory:' AS aux91;
.quit
.stats stmt
ATTACH DATABASE ':memory:' AS aux90;
BEGIN EXCLUSIVE TRANSACTION;
CREATE TABLE [T] (
  A VARCHAR(-CAST(CAST((x'df3f91c000' + NULL) AS CLOB) AS  INTEGER)),
  B VARCHAR(jsonb_extract(-(-(json_array_length(unhex(substr(NULL, zeroblob(-CAST(CAST((char(NULL) + glob('*helium*', x'')) ->> '$.key' AS REAL) AS VARCHAR(-(-(if(unhex('4'), nan, json_type(instr(randomblob(upper(123)), randomblob(2)), '$'), 255, 0, 255)))))), 1)), '$'))), '$')),
  C VARCHAR(30),
  PRIMARY KEY (A, B),
  UNIQUE (A, C)
);
INSERT INTO "T" VALUES ('a', 'p', 'x');
INSERT INTO main.T VALUES ('a', 'q', 'y');
INSERT INTO T VALUES ('b', 'p', 'z');
INSERT INTO T VALUES ('c', 'r', 'w');
INSERT INTO T VALUES ('d', 's', 'v');
WITH _m AS MATERIALIZED (WITH _m AS MATERIALIZED (SELECT * FROM T) SELEC_m * FROM T) SELEC_m A, COUNT(DISTINCT B) AS D FROM T GROUP BY A HavInG COUNT(DISTINCT B) IS NOT 1;
PRAGMA secure_delete >= 1;
COMMIT;
INSERT INTO T SELECT * FROM T;
DETACH DATABASE aux90;
CREATE TEMP  VIEW IF NOT EXISTS v_T_4205 AS SELECT A FROM T;
WITH RECURSIVE cnt(x) AS (VALUES(1) UNION SELECT x+1 FROM cnt WHERE NOT NOT (NOT NOT (NOT NOT NOT NOT (x<9) SELECT * FROM cnt))) ;
ALTER TABLE T ADD COLUMN extra_7799 SMALLINT DEFAULT (random());
DETACH DATABASE aux91;
CREATE UNIQUE  INDEX IF NOT EXISTS idx_T_2472 ON T(B COLLATE NOCASE);
COMMIT TRANSACTION;
SELECT COUNT(*) FILTER (WHERE B IS NOT NULL), SUM(rowid) FILTER (WHERE +B > 0), COUNT(*) FILTER (WHERE 1=0), COUNT(*) FILTER (WHERE 1=1), COUNT(*) FILTER (WHERE /* if(1, {v}, 1/0) */ NULL), AVG(B) FILTER (WHERE B > 0 AND B < 100), COUNT(*) FILTER (WHERE typeof(B) = "text") FROM T;
WITH cte AS (SELECT B FROM T) SELECT * FROM cte;
SELECT AVG(B) FROM T;
ALTER TABLE T ADD COLUMN extra_3225 FLOAT COLLATE RTRIM;
SELECT LAG(A, 1) OVER (PARTITION BY A ORDER BY A ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE GROUP) FROM T;
BEGIN DEFERRED;
-- jsonb_extract({v}, '$.key')

ATTACH DATABASE ':memory:' AS aux91;
.quit
.stats stmt
ATTACH DATABASE ':memory:' AS aux90;
BEGIN EXCLUSIVE TRANSACTION;
CREATE TABLE T (
  A VARCHAR(-CAST(CAST(4817548806300799530 AS REAL) AS INTEGER)),
  B VARCHAR(30),
  C VARCHAR(30),
  PRIMARY KEY (A, B),
  UNIQUE (A, C)
);
INSERT INTO T VALUES ('a', 'p', 'x');
INSERT INTO T VALUES ('a', 'q', 'y');
INSERT INTO T VALUES ('b', 'p', 'z');
INSERT INTO T VALUES ('c', 'r', 'w');
INSERT INTO T VALUES ('d', 's', 'v');
WITH _m AS MATERIALIZED (SELECT * FROM T) SELEC_m A, COUNT(DISTINCT B) AS D FROM T GROUP BY A HAVING COUNT(DISTINCT B) == 1;
PRAGMA secure_delete = 1;
COMMIT;
INSERT INTO T SELECT * FROM T;
DETACH DATABASE aux90;
CREATE TEMP  VIEW IF NOT EXISTS v_T_4205 AS SELECT A FROM T;
WITH RECURSIVE cnt(x) AS (VALUES(1) UNION SELECT x+1 FROM cnt WHERE x<9) SELECT * FROM cnt;
ALTER TABLE T ADD COLUMN extra_7799 SMALLINT DEFAULT (random());
DETACH DATABASE aux91;
CREATE UNIQUE  INDEX IF NOT EXISTS idx_T_2472 ON T(B COLLATE NOCASE);
CREATE TABLE T (
  a INTEGER,
  b TEXT,
  c REAL,
  d REAL
);
INSERT INTO T VALUES (1,'a',40.5,-70.0), (2,'b',-10.25,20.5), (3,'c',9e999,-9e999);
SELECT b FROM T WHERE ABS(c) > 5 AND ABS(d) > 5;
COMMIT TRANSACTION;
SELECT COUNT(*) FILTER (WHERE B IS NOT NULL), SUM(rowid) FILTER (WHERE B > 0), COUNT(*) FILTER (WHERE 1=0), COUNT(*) FILTER (WHERE 1=1), COUNT(*) FILTER (WHERE /* if(1, {v}, 1/0) */ NULL), AVG(B) FILTER (WHERE B > 0 AND B < 100), COUNT(*) FILTER (WHERE typeof(B) = "text") FROM T;
WITH cte AS (SELECT B FROM T) SELECT * FROM cte;
SELECT AVG(B) FROM T;
ALTER TABLE T ADD COLUMN extra_3225 FLOAT COLLATE RTRIM;
SELECT LAG(A, 1) OVER (PARTITION BY A ORDER BY A ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE GROUP) FROM T;
BEGIN DEFERRED;
-- jsonb_extract({v}, '$.key')

ATTACH DATABASE ':memory:' /**/ AS aux91;
.quit
.stats stmt
ATTACH DATABASE ':memory:' AS aux90;
BEGIN EXCLUSIVE TRANSACTION;
CREATE TABLE T (
  A VARCHAR(-CAST(CAST(4817548806300799530 AS REAL) AS INTEGER)),
  B VARCHAR(30),
  C VARCHAR(30),
  PRIMARY KEY (A, B),
  UNIQUE (A, C)
);
INSERT INTO T VALUES ('a', 'p', 'x');
INSERT INTO T VALUES ('a', 'q', 'y');
INSERT INTO T VALUES ('b', 'p', 'z');
INSERT INTO T VALUES ('c', 'r', 'w');
INSERT INTO T VALUES ('d', 's', 'v');
WITH _m AS MATERIALIZED (SELECT * FROM T) SELEC_m A, COUNT(DISTINCT B) AS D FROM T GROUP BY A HAVING COUNT(DISTINCT B) == 1;
PRAGMA secure_delete = 1;
COMMIT;
INSERT INTO T SELECT * FROM T;
DETACH DATABASE aux90;
CREATE TABLE main.T1 (
  A VARCHAR(15) PRIMARY KEY,
  B VARCHAR(30) NOT NULL UNIQUE
);
CREATE TABLE T2 (
  A VARCHAR(10) PRIMARY KEY,
  X VARCHAR(15) NOT NULL,
  C BIGINT,
  FOREIGN KEY (X) REFERENCES T1(A)
);
INSERT INTO T1 VALUES ('p', 'x');
INSERT INTO T1 VALUES ('q', 'y');
INSERT INTO T2 VALUES ('a', 'p', 9223372036854775807);
INSERT INTO T2 VALUES ('b', 'q', -9223372036854775808);
SELECT X, SUM(C) AS D, COUNT(*) AS E FROM T2 GROUP BY X;
CREATE TEMP  VIEW IF NOT EXISTS v_T_4205 AS SELECT A FROM T;
WITH RECURSIVE cnt(x) AS (VALUES(1) UNION SELECT x+1 FROM cnt WHERE x<9) SELECT * FROM cnt;
ALTER TABLE T ADD COLUMN extra_7799 SMALLINT DEFAULT (random());
DETACH DATABASE aux91;
CREATE UNIQUE  INDEX IF NOT EXISTS idx_T_2472 ON T(B COLLATE NOCASE);
COMMIT TRANSACTION;
SELECT COUNT(*) FILTER (WHERE B IS NOT NULL), SUM(rowid) FILTER (WHERE B > 0), COUNT(*) FILTER (WHERE 1=0), COUNT(*) FILTER (WHERE 1=1), COUNT(*) FILTER (WHERE /* if(1, {v}, 1/0) */ NULL), AVG(B) FILTER (WHERE B > 0 AND B < 100), COUNT(*) FILTER (WHERE typeof(B) = "text") FROM T;
WITH cte AS (SELECT B FROM T) SELECT * FROM cte;
SELECT AVG(B) FROM T;
ALTER TABLE T ADD COLUMN extra_3225 FLOAT COLLATE RTRIM;
SELECT LAG(A, 1) OVER (PARTITION BY A ORDER BY A ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE GROUP) FROM T;
BEGIN DEFERRED;
-- jsonb_extract({v}, '$.key')

ATTACH DATABASE ':memory:' AS aux91;
.quit
.stats stmt
ATTACH DATABASE ':memory:' AS aux90;
BEGIN EXCLUSIVE TRANSACTION;
CREATE TABLE T (
  A VARCHAR(-CAST(CAST(4817548806300799530 AS REAL) AS INTEGER)),
  B VARCHAR(30),
  C VARCHAR(30),
  PRIMARY KEY (A, B),
  UNIQUE (A, C)
);
INSERT INTO T VALUES ('a', 'p', 'x');
INSERT INTO T VALUES ('a', 'q', 'y');
INSERT INTO T VALUES ('b', 'p', 'z');
INSERT INTO T VALUES ('c', 'r', 'w');
INSERT INTO T VALUES ('d', 's', 'v');
WITH _m AS MATERIALIZED (SELECT * FROM T) SELEC_m A, COUNT(DISTINCT B) AS D FROM T GROUP BY A HAVING COUNT(DISTINCT B) == 1;
PRAGMA secure_delete = 1;
COMMIT;
INSERT INTO T SELECT * FROM T;
DETACH DATABASE aux90;
CREATE TEMP  VIEW IF NOT EXISTS v_T_4205 AS SELECT A FROM T;
WITH RECURSIVE cnt(x) AS (VALUES(1) UNION SELECT x+1 FROM cnt WHERE x<9) SELECT * FROM cnt;
ALTER TABLE T ADD COLUMN extra_7799 SMALLINT DEFAULT (random());
DETACH DATABASE aux91;
CREATE UNIQUE  INDEX IF NOT EXISTS idx_T_2472 ON T(B COLLATE NOCASE);
COMMIT TRANSACTION;
SELECT COUNT(*) FILTER (WHERE B IS NOT NULL), SUM(rowid) FILTER (WHERE B > 0), COUNT(*) FILTER (WHERE 1=0), COUNT(*) FILTER (WHERE 1=1), COUNT(*) FILTER (WHERE /* if(1, {v}, 1/0) */ NULL), AVG(B) FILTER (WHERE B > 0 AND B < 100), COUNT(*) FILTER (WHERE typeof(B) = "text") FROM  T;
WITH cte AS (SELECT B FROM T) SELECT * FROM cte;
SELECT AVG(B) FROM T;
ALTER TABLE T ADD COLUMN extra_3225 FLOAT COLLATE RTRIM;
SELECT LAG(A, 1) OVER (PARTITION BY A ORDER BY A ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE GROUP) FROM T;
BEGIN DEFERRED;
-- jsonb_extract({v}, '$.key')

ATTACH DATABASE ':memory:' AS aux91;
.quit
.stats stmt
ATTACH DATABASE ':memory:' AS aux90;
BEGIN EXCLUSIVE TRANSACTION;
CREATE TABLE T (
  A VARCHAR(-CAST(CAST(4817548806300799530 AS REAL) AS INTEGER)),
  B VARCHAR(30),
  C VARCHAR(30),
  PRIMARY KEY (A, B),
  UNIQUE (A, C)
);
INSERT INTO T VALUES ('a', 'p', 'x');
INSERT INTO T VALUES ('a', 'q', 'y');
INSERT INTO T VALUES ('b', 'p', 'z');
INSERT INTO T VALUES ('c', 'r', 'w');
INSERT INTO T VALUES ('d', 's', 'v');
WITH _m AS MATERIALIZED (SELECT * FROM T) SELEC_m A, COUNT(DISTINCT B) AS D FROM T GROUP BY A HAVING COUNT(DISTINCT B) == 1;
PRAGMA secure_delete = 1;
COMMIT;
INSERT INTO T SELECT * FROM T;
DETACH DATABASE aux90;
CREATE TEMP  VIEW IF NOT EXISTS v_T_4205 AS SELECT A FROM T;
WITH RECURSIVE cnt(x) AS (VALUES(1) UNION SELECT x+1 FROM cnt WHERE x<9) SELECT * FROM cnt;
ALTER TABLE T ADD COLUMN extra_7799 SMALLINT DEFAULT (random());
DETACH DATABASE aux91;
CREATE UNIQUE  INDEX IF NOT EXISTS idx_T_2472 ON T(B COLLATE NOCASE);
COMMIT TRANSACTION;
SELECT COUNT(*) FILTER (WHERE B IS NOT NULL), SUM(rowid) FILTER (WHERE B > 0), COUNT(*) FILTER (WHERE 1=0), COUNT(*) FILTER (WHERE 1=1), COUNT(*) FILTER (WHERE /* if(1, {v}, 1/0) */ NULL), AVG(B) FILTER (WHERE B > 0 AND B < 100), COUNT(*) FILTER (WHERE typeof(B) = "text") FROM T;
WITH cte AS (SELECT B FROM T) SELECT * FROM cte;
SELECT AVG(B) FROM T;
ALTER TABLE T ADD COLUMN extra_3225 FLOAT COLLATE RTRIM;
SELECT LAG(A, 1) OVER (PARTITION BY A ORDER BY A ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE GROUP) FROM T;
REINDEX;
ANALYZE;
REINDEX;
ALTER TABLE T RENAME TO T_r2245;
ANALYZE T;
SELECT * FROM T;
SELECT * FROM T NATURAL JOIN T;
SELECT C FROM T INTERSECT SELECT C FROM (SELECT * FROM T) AS sub;
SELECT AVG(C) FROM T;
ALTER TABLE T RENAME TO T_r2444;
SELECT TOTAL(C) FROM T;
SELECT * FROM T AS a RIGHT OUTER JOIN T AS b ON a.rowid = b.rowid;
INSERT INTO T DEFAULT VALUES;
SELECT SUM(C) FILTER (WHERE 1=0) OVER (ORDER BY C ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW EXCLUDE TIES) FROM T;
CREATE TABLE T (
  A VARCHAR(20),
  B VARCHAR(10),
  PRIMARY KEY (A, B)
);
INSERT INTO T VALUES ('a', 'p');
INSERT INTO T VALUES ('a', 'q');
INSERT INTO T VALUES ('b', 'q');
INSERT INTO T VALUES ('c', 'r');
INSERT INTO T VALUES ('b', 'r');
INSERT INTO T VALUES ('b', 't');
SELECT B, COUNT(DISTINCT A) AS D FROM T GROUP BY B ORDER BY D DESC, B ASC;
CREATE TRIGGER IF NOT EXISTS trg_T_5369 AFTER UPDATE OF B ON T FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'abort'); END;
REINDEX;
REINDEX T;
ALTER TABLE T RENAME TO T_r6168;
ALTER TABLE T DROP COLUMN B;
ALTER TABLE T RENAME /**/ COLUMN A TO A_r4813;
CREATE TRIGGER IF NOT EXISTS trg_T_9600 AFTER DELETE ON T BEGIN INSERT INTO T(B) VALUES (NULL); END;
CREATE UNIQUE  INDEX IF NOT EXISTS idx_T_7703 ON T((A + 1)) WHERE A > 0;
SELECT TOTAL(A) FROM T;
CREATE  VIEW IF NOT EXISTS v_T_7018 AS SELECT B FROM T;
CREATE  VIEW IF NOT EXISTS v_T_8737 AS SELECT B FROM T;
DELETE FROM T WHERE 1 RETURNING *;
REINDEX T;
DETACH DATABASE aux67;
ANALYZE;
SELECT * FROM T WHERE EXISTS (SELECT 1 FROM T);
SELECT COUNT(*) FROM T;
UPDATE T SET B = CURRENT_TIMESTAMP WHERE 1;
SELECT * FROM T WHERE EXISTS (SELECT 1 FROM T WHERE B < 0);
SELECT MIN(A) FROM T;
INSERT INTO T DEFAULT VALUES;
INSERT OR REPLACE INTO T VALUES (0, NULL);
ROLLBACK TO sp6286;
RELEASE sp6286;
UPDATE T SET B = 'x' WHERE rowid = 1;
SELECT * FROM T NATURAL JOIN T;
ALTER TABLE T ADD COLUMN extra_1003 VARCHAR(255) DEFAULT (random());
SELECT * FROM T NATURAL JOIN T;
WITH cte AS (SELECT * FROM T), cte2 AS (SELECT * /**/ FROM cte) SELECT * FROM cte2;
ALTER TABLE T DROP COLUMN B;
SELECT COUNT(*) FILTER (WHERE B IS NOT NULL), SUM(rowid) FILTER (WHERE B > 0), COUNT(*) FILTER (WHERE 1=0), COUNT(*) FILTER (WHERE 1=1), COUNT(*) FILTER (WHERE NULL), AVG(B) FILTER (WHERE B > 0 AND B < 100), COUNT(*) FILTER (WHERE typeof(B) = "text") FROM T;
SELECT * FROM T NATURAL JOIN T;
INSERT INTO T DEFAULT VALUES;
INSERT INTO T VALUES (NULL, NULL);
SELECT * FROM T WHERE B IN (SELECT B FROM T t2 WHERE t2.B = T.B);
CREATE TEMP  VIEW IF NOT EXISTS v_T_7633 AS SELECT B FROM T;
WITH RECURSIVE fib(a,b,n) AS (VALUES(1,1,1) UNION ALL SELECT b, a+b, n+1 FROM fib WHERE n<26) SELECT a, n FROM fib;
DELETE FROM T WHERE 0;
INSERT OR REPLACE INTO T VALUES (NULL, 0);
DETACH DATABASE aux87;
INSERT INTO T VALUES (NULL, NULL);
CREATE TEMP  VIEW IF NOT EXISTS v_T_6663 AS SELECT A FROM T;
DETACH DATABASE aux43;
INSERT INTO T SELECT * FROM T;
REINDEX T;
CREATE TABLE T (
  a INTEGER,
  b REAL,
  c REAL
);
INSERT INTO T VALUES (1,1.5,10.0), (2,-2.5,20.0), (3,-9e999,30.0);
SELECT * FROM T WHERE b < 2.0 ORDER BY b;
UPDATE T1 SET A = 'x' WHERE A BETWEEN 0 AND 100;
SELECT COUNT(*) FILTER (WHERE B IS NOT NULL), SUM(rowid) FILTER (WHERE B > 0), COUNT(*) FILTER (WHERE 1=0), COUNT(*) FILTER (WHERE 1=1), COUNT(*) FILTER (WHERE NULL), AVG(B) FILTER (WHERE B > 0 AND B < 100), COUNT(*) FILTER (WHERE typeof(B) = "text") FROM T1;
INSERT INTO T2 VALUES (NULL, 'x', 'x') ON CONFLICT(A) DO UPDATE SET A = excluded.A, X = excluded.X, C = excluded.C;
CREATE TEMP  VIEW IF NOT EXISTS v_T1_7488 AS SELECT A FROM T1;
CREATE TEMPORARY  VIEW IF NOT EXISTS v_T2_4067 AS SELECT C FROM T2;
INSERT OR REPLACE INTO T1 VALUES ('x', 'x');
VACUUM;
WITH RECURSIVE fib(a,b) AS (VALUES(1,1) UNION ALL SELECT b, a+b FROM fib WHERE b<1000) SELECT a FROM fib;
SELECT COUNT(*) FILTER (WHERE c IS NOT NULL), SUM(rowid) FILTER (WHERE c > 0), COUNT(*) FILTER (WHERE 1=0), COUNT(*) FILTER (WHERE 1=1), COUNT(*) FILTER (WHERE NULL), AVG(c) FILTER (WHERE c > 0 AND c < 100), COUNT(*) FILTER (WHERE typeof(c) = "text") FROM T;
SELECT * FROM T AS a FULL JOIN T1 AS b ON a.rowid = b.rowid;
PRAGMA automatic_index = ON;
CREATE  VIEW IF NOT EXISTS v_T1_4724 AS SELECT B FROM T1;
SELECT c FROM T EXCEPT SELECT c FROM (SELECT * FROM T) AS sub;

SELECT COUNT(*) FROM T2;
SELECT COUNT(*) FILTER (WHERE C IS NOT NULL), SUM(rowid) FILTER (WHERE C > 0), COUNT(*) FILTER (WHERE 1=0), COUNT(*) FILTER (WHERE 1=1), COUNT(*) FILTER (WHERE NULL), AVG(C) FILTER (WHERE C > 0 AND C < 100), COUNT(*) FILTER (WHERE typeof(C) = "text") FROM T2;
ALTER TABLE T2 RENAME TO T2_r7098;
```

## 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|1
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|1
von|20|2
Braun|30
Wernher|10
von|20
```

## Flag

```

```

