## 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
.tables non_existent_table
BEGIN EXCLUSIVE;
SAVEPOINT sp2502;
ATTACH DATABASE ('' || (':memory:') || '') AS aux5;
CREATE TABLE main.t1(a NUMERIC PRIMARY KEY, b TEXT, c INT, d INT);
InserT INTO t1 VALUES (CAST('.' AS FLOA), 'Wernher', acosh(log(-NULL, instr(NULL, NULL))), (100 - 0));
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
PRAGMA pragma_list;
CREATE TABLE T1 (
  A VARCHAR(-(-(hex(2790980413263895699)))),
  X VARCHAR(10),
  PRIMARY KEY (A, X),
  UNIQUE (X)
);
CREATE TABLE T2 (
  A VARCHAR(20),
  Y VARCHAR(10) UNIQUE,
  PRIMARY KEY (A, Y)
);
INSErT INTO T1 VALUES ('a', 'm');
INSERT INTO T1 VALUES ('b', 'n');
INSERT INTO T2 VALUES ('b', 'k');
WITH _m /* ifnull(NULL, {v}) */ AS MATERIALIZED (SELECT * FROM T1) SELECT A FROM _m UNION ALL SELECT A FROM T2 ORDER BY A;
SELECT * FROM T1 INNER JOIN T1;
ALTER TABLE T1 ADD COLUMN extra_1763 NCHAR(55);
ALTER TABLE T2 RENAME TO T2_r7203;
ALTER TABLE T2 DROP COLUMN Y;
CREATE UNIQUE  INDEX IF NOT EXISTS idx_T1_4762 ON T1((A + 1)) WHERE NOT NOT (NOT NOT (NOT NOT (A IS NOT NULL))) ;
ANALYZE T2;
REINDEX T2;
INSERT INTO T2 VALUES ('x', 1) ON CONFLICT(A) DO UPDATE SET A = excluded.A, Y = excluded.Y;
INSERT AND FAIL INTO T2 VALUES (1, 'x');
SELECT LAST_VALUE(A) OVER (ORDER BY A ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE GROUP) FROM T2;
INSERT INTO T2 VALUES (NULL, NULL);
DETACH DATABASE aux5;
SELECT * FROM T2 WHERE A IN (SELECT A FROM T2);
INSERT INTO T2 VALUES ('x', 1) ON CONFLICT(A) DO UPDATE SET A = excluded.A, Y = excluded.Y;
INSERT INTO t1 DEFAULT VALUES;
UPDATE t1 SET a = a + 1 WHERE a IS NOT NULL RETURNING *;
ANALYZE;
INSERT OR REPLACE INTO T1 VALUES (0, '');
SELECT * FROM T1 NATURAL JOIN T2;
DELETE FROM t1 WHERE +b > (SELECT AVG(b) FROM t1);
ALTER TABLE T2 DROP COLUMN Y;
ROLLBACK TO sp2502;
RELEASE sp2502;
PRAGMA auto_vacuum = 1;
SELECT * FROM T2;
SAVEPOINT sp2502;
ATTACH DATABASE ':memory:' AS aux5;
CREATE TABLE t1(a NUMERIC PRIMARY KEY, b TEXT, c INT, d INT);
INSERT INTO t1 VALUES (CAST('.' AS FLOA), '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
PRAGMA pragma_list;
CREATE TABLE T1 (
  A VARCHAR(-(-(hex(2790980413263895699)))),
  X VARCHAR(10),
  PRIMARY KEY (A, X),
  UNIQUE (X)
);
CREATE TABLE T2 (
  A VARCHAR(20),
  Y VARCHAR(10) UNIQUE,
  PRIMARY KEY (A, Y)
);
INSErT INTO T1 VALUES ('a', 'm');
INSERT INTO T1 VALUES ('b', 'n');
INSERT INTO T2 VALUES ('b', 'k');
WITH _m /* ifnull(NULL, {v}) */ AS MATERIALIZED (SELECT * FROM T1) SELECT A FROM _m UNION ALL SELECT A FROM T2 ORDER BY A;
SELECT * FROM T1 NATURAL JOIN T1;
ALTER TABLE T1 ADD COLUMN extra_1763 NCHAR(55);
ALTER TABLE T2 RENAME TO T2_r7203;
ALTER TABLE T2 DROP COLUMN Y;
CREATE UNIQUE  INDEX IF NOT EXISTS idx_T1_4762 ON T1((A + 1)) WHERE A IS NOT NULL;
ANALYZE T2;
REINDEX T2;
INSERT INTO T2 VALUES ('x', 1) ON CONFLICT(A) DO UPDATE SET A = excluded.A, Y = excluded.Y;
INSERT OR FAIL INTO T2 VALUES (1, 'x');
SELECT LAST_VALUE(A) OVER (ORDER BY A ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE GROUP) FROM T2;
INSERT INTO T2 VALUES (NULL, NULL);
DETACH DATABASE aux5;
SELECT * FROM T2 WHERE A IN (SELECT A FROM T2);
INSERT INTO T2 VALUES ('x', 1) ON CONFLICT(A) DO UPDATE SET A = excluded.A, Y = excluded.Y;
INSERT INTO t1 DEFAULT VALUES;
UPDATE t1 SET a = a + 1 WHERE a IS NOT NULL RETURNING *;
ANALYZE;
INSERT OR REPLACE INTO T1 VALUES (0, '');
SELECT * FROM T1 NATURAL JOIN T2;
DELETE FROM t1 WHERE b > (SELECT AVG(b) FROM t1);
ALTER TABLE T2 DROP COLUMN Y;
ROLLBACK TO sp2502;
RELEASE sp2502;
PRAGMA auto_vacuum = 1;
SELECT * FROM T2;
SAVEPOINT sp2502;
ATTACH DATABASE ':memory:' AS aux5;
CREATE TABLE t1(a NUMERIC PRIMARY KEY, b TEXT, c INT, d INT);
INSERT INTO t1 VALUES (CAST('.' AS FLOA), '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
PRAGMA pragma_list;
CREATE TABLE T1 (
  A VARCHAR(-(-(hex(2790980413263895699)))),
  X VARCHAR(10),
  PRIMARY KEY (A, X),
  UNIQUE (X)
);
CREATE TABLE T2 (
  A VARCHAR(20),
  Y VARCHAR(10) UNIQUE,
  PRIMARY KEY (A, Y)
);
INSErT INTO T1 VALUES ('a', 'm');
INSERT INTO T1 VALUES ('b', 'n');
INSERT INTO T2 VALUES ('b', 'k');
WITH _m /* ifnull(NULL, {v}) */ AS MATERIALIZED (SELECT * FROM T1) SELECT A FROM _m UNION ALL SELECT A FROM T2 ORDER BY A;
SELECT * FROM T1 NATURAL JOIN T1;
ALTER TABLE T1 ADD COLUMN extra_1763 NCHAR(55);
ALTER TABLE T2 RENAME TO T2_r7203;
ALTER TABLE T2 DROP COLUMN Y;
CREATE UNIQUE  INDEX IF NOT EXISTS idx_T1_4762 ON T1((A + 1)) WHERE A IS NOT NULL;
ANALYZE T2;
REINDEX T2;
INSERT INTO T2 VALUES ('x', 1) ON CONFLICT(A) DO UPDATE SET A = excluded.A, Y = excluded.Y;
INSERT OR FAIL INTO T2 VALUES (1, 'x');
SELECT LAST_VALUE(A) OVER (ORDER BY A ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE GROUP) FROM T2;
INSERT INTO T2 VALUES (NULL, NULL);
DETACH DATABASE aux5;
SELECT * FROM T2 WHERE A IN (SELECT A FROM T2);
INSERT INTO T2 VALUES ('x', 1) ON CONFLICT(A) DO UPDATE SET A = excluded.A, Y = excluded.Y;
INSERT INTO t1 DEFAULT VALUES;
UPDATE t1 SET a = a + 1 WHERE a IS NOT NULL RETURNING *;
ANALYZE;
INSERT OR REPLACE INTO T1 VALUES (0, '');
SELECT * FROM T1 NATURAL JOIN T2;
DELETE FROM t1 WHERE b > (SELECT AVG(b) FROM t1);
CREATE TABLE T1 (
  A VARCHAR(20) PRIMARY KEY,
  X VARCHAR(10) UNIQUE
);
CREATE TABLE T2 (
  A VARCHAR(20) PRIMARY KEY,
  Y VARCHAR(10) UNIQUE
);
INSERT INTO T1 VALUES ('a', 'm');
INSERT INTO T1 VALUES ('b', 'n');
INSERT INTO T1 VALUES ('c', 'o');
INSERT INTO T2 VALUES ('b', 'k');
INSERT INTO T2 VALUES ('c', 'l');
SELECT A FROM T1 INTERSECT SELECT A FROM T2;
ALTER TABLE T2 DROP COLUMN Y;
ROLLBACK TO sp2502;
RELEASE sp2502;
PRAGMA auto_vacuum = 1;
SELECT * FROM T2;
SAVEPOINT sp2502;
ATTACH DATABASE ':memory:' AS aux5;
CREATE TABLE t1(a NUMERIC PRIMARY KEY, b TEXT, c INT, d INT);
INSERT INTO t1 VALUES (CAST('.' AS FLOA), '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
PRAGMA pragma_list;
CREATE TABLE T1 (
  A VARCHAR(-(-(hex(2790980413263895699)))),
  X VARCHAR(10),
  PRIMARY KEY (A, X),
  UNIQUE (X)
);
CREATE TABLE T2 (
  A VARCHAR(20),
  Y VARCHAR(10) UNIQUE,
  PRIMARY KEY (A, Y)
);
INSErT INTO T1 VALUES ('a', 'm');
INSERT INTO T1 VALUES ('b', 'n');
INSERT INTO T2 VALUES ('b', 'k');
WITH _m /* ifnull(NULL, {v}) */ AS MATERIALIZED (SELECT * FROM T1) SELECT A FROM _m UNION ALL SELECT A FROM T2 ORDER BY A;
SELECT * FROM T1 NATURAL JOIN T1;
ALTER TABLE T1 ADD COLUMN extra_1763 NCHAR(55);
ALTER TABLE T2 RENAME TO T2_r7203;
ALTER TABLE T2 DROP COLUMN Y;
CREATE UNIQUE  INDEX IF NOT EXISTS idx_T1_4762 ON T1((A + 1)) WHERE A IS NOT NULL;
ANALYZE T2;
REINDEX T2;
INSERT INTO T2 VALUES ('x', 1) ON CONFLICT(A) DO UPDATE SET A = excluded.A, Y = excluded.Y;
INSERT OR FAIL INTO T2 VALUES (1, 'x');
SELECT LAST_VALUE(A) OVER (ORDER BY A ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE GROUP) FROM T2;
INSERT INTO T2 VALUES (NULL, NULL);
DETACH DATABASE aux5;
SELECT * FROM T2 WHERE A IN (SELECT A FROM T2);
INSERT INTO T2 VALUES ('x', 1) ON CONFLICT(A) DO UPDATE SET A = excluded.A, Y = excluded.Y;
INSERT INTO t1 DEFAULT VALUES;
UPDATE t1 SET a = a + 1 WHERE a IS NOT NULL RETURNING *;
ANALYZE;
INSERT OR REPLACE INTO T1 VALUES (0, '');
SELECT * FROM T1 NATURAL JOIN T2;
DELETE FROM t1 WHERE b > (SELECT AVG(b) FROM t1);
ALTER TABLE T2 DROP COLUMN Y;
ROLLBACK TO sp2502;
RELEASE sp2502;
PRAGMA auto_vacuum = 1;
SELECT * FROM T2;
SAVEPOINT sp2502;
ATTACH DATABASE ':memory:' AS aux5;
CREATE TABLE t1(a NUMERIC PRIMARY KEY, b TEXT, c INT, d INT);
INSERT INTO t1 VALUES (CAST('.' AS FLOA), '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
PRAGMA pragma_list;
CREATE TABLE T1 (
  A VARCHAR(-(-(hex(2790980413263895699)))),
  X VARCHAR(10),
  PRIMARY KEY (A, X),
  UNIQUE (X)
);
CREATE TABLE T2 (
  A VARCHAR(20),
  Y VARCHAR(10) UNIQUE,
  PRIMARY KEY (A, Y)
);
INSErT INTO T1 VALUES ('a', 'm');
INSERT INTO T1 VALUES ('b', 'n');
INSERT INTO T2 VALUES ('b', 'k');
WITH _m /* ifnull(NULL, {v}) */ AS MATERIALIZED (SELECT * FROM T1) SELECT A FROM _m UNION ALL SELECT A FROM T2 ORDER BY A;
SELECT * FROM T1 NATURAL JOIN T1;
ALTER TABLE T1 ADD COLUMN extra_1763 NCHAR(55);
ALTER TABLE T2 RENAME TO T2_r7203;
ALTER TABLE T2 DROP COLUMN Y;
CREATE UNIQUE  INDEX IF NOT EXISTS idx_T1_4762 ON T1((A + 1)) WHERE A IS NOT NULL;
ANALYZE T2;
REINDEX T2;
INSERT INTO T2 VALUES ('x', 1) ON CONFLICT(A) DO UPDATE SET A = excluded.A, Y = excluded.Y;
INSERT OR FAIL INTO T2 VALUES (1, 'x');
SELECT LAST_VALUE(A) OVER (ORDER BY A ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE GROUP) FROM T2;
INSERT INTO T2 VALUES (NULL, NULL);
DETACH DATABASE aux5;
SELECT * FROM T2 WHERE A IN (SELECT A FROM T2);
INSERT INTO T2 VALUES ('x', 1) ON CONFLICT(A) DO UPDATE SET A = excluded.A, Y = excluded.Y;
INSERT INTO t1 DEFAULT VALUES;
UPDATE t1 SET a = a + 1 WHERE a IS NOT NULL RETURNING *;
ANALYZE;
INSERT OR REPLACE INTO T1 VALUES (0, '');
SELECT * FROM T1 NATURAL JOIN T2;
DELETE FROM t1 WHERE b > (SELECT AVG(b) FROM t1);
ALTER TABLE T2 DROP COLUMN Y;
ROLLBACK TO sp2502;
RELEASE sp2502;
PRAGMA auto_vacuum = 1;
SELECT * FROM T2;
SAVEPOINT sp2502;
ATTACH DATABASE ':memory:' AS aux5;
CREATE TABLE t1(a NUMERIC PRIMARY KEY, b TEXT, c INT, d INT);
INSERT INTO t1 VALUES (CAST('.' AS FLOA), '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
PRAGMA pragma_list;
CREATE TABLE T1 (
  A VARCHAR(-(-(hex(2790980413263895699)))),
  X VARCHAR(10),
  PRIMARY KEY (A, X),
  UNIQUE (X)
);
CREATE TABLE T2 (
  A VARCHAR(20),
  Y VARCHAR(10) UNIQUE,
  PRIMARY KEY (A, Y)
);
INSErT INTO T1 VALUES ('a', 'm');
INSERT INTO T1 VALUES ('b', 'n');
INSERT INTO T2 VALUES ('b', 'k');
WITH _m /* ifnull(NULL, {v}) */ AS MATERIALIZED (SELECT * FROM T1) SELECT A FROM _m UNION ALL SELECT A FROM T2 ORDER BY A;
SELECT * FROM T1 NATURAL JOIN T1;
ALTER TABLE T1 ADD COLUMN extra_1763 NCHAR(55);
ALTER TABLE T2 RENAME TO T2_r7203;
ALTER TABLE T2 DROP COLUMN Y;
CREATE UNIQUE  INDEX IF NOT EXISTS idx_T1_4762 ON T1((A + 1)) WHERE A IS NOT NULL;
ANALYZE T2;
REINDEX T2;
INSERT INTO T2 VALUES ('x', 1) ON CONFLICT(A) DO UPDATE SET A = excluded.A, Y = excluded.Y;
INSERT OR FAIL INTO T2 VALUES (1, 'x');
SELECT LAST_VALUE(A) OVER (ORDER BY A ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE GROUP) FROM T2;
INSERT INTO T2 VALUES (NULL, NULL);
DETACH DATABASE aux5;
SELECT * FROM T2 WHERE A IN (SELECT A FROM T2);
INSERT INTO T2 VALUES ('x', 1) ON CONFLICT(A) DO UPDATE SET A = excluded.A, Y = excluded.Y;
INSERT INTO t1 DEFAULT VALUES;
UPDATE t1 SET a = a + 1 WHERE a IS NOT NULL RETURNING *;
ANALYZE;
INSERT OR REPLACE INTO T1 VALUES (0, '');
SELECT * FROM T1 NATURAL JOIN T2;
DELETE FROM t1 WHERE b > (SELECT AVG(b) FROM t1);
ALTER TABLE T2 DROP COLUMN Y;
ROLLBACK TO sp2502;
RELEASE sp2502;
PRAGMA auto_vacuum = 1;
SELECT * FROM T2;
VACUUM;
PRAGMA vdbe_listing = 0;
SELECT COUNT(*) FROM T2;
SELECT * FROM t1 AS a JOIN t1 AS b ON a.rowid = b.rowid;
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 T2;
CREATE TEMP  VIEW IF NOT EXISTS v_t1_6450 AS SELECT d FROM t1;
SELECT * FROM T2 WHERE A > ALL (SELECT A FROM T2);
SELECT COUNT(*) FILTER (WHERE A > 0) OVER (PARTITION BY A ORDER BY A ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW EXCLUDE TIES) FROM T1;
ALTER TABLE T2 RENAME COLUMN Y TO Y_r4134;
INSERT OR ABORT INTO t1 VALUES ('x', NULL, 'x', -5);
SELECT STRING_AGG(c) FROM t1;
ALTER TABLE T1 DROP COLUMN A;
CREATE TRIGGER IF NOT EXISTS trg_T2_9285 AFTER DELETE ON T2 FOR EACH ROW BEGIN INSERT INTO T2(Y) VALUES (NULL); END;
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;
SELECT COUNT(*) FILTER (WHERE X IS NOT NULL), SUM(rowid) FILTER (WHERE X > 0), COUNT(*) FILTER (WHERE 1=0), COUNT(*) FILTER (WHERE 1=1), COUNT(*) FILTER (WHERE NULL), AVG(X) FILTER (WHERE X > 0 AND X < 100), COUNT(*) FILTER (WHERE typeof(X) = "text") FROM T1;
REINDEX;
DROP VIEW IF EXISTS t1;
SELECT * FROM T1 AS a RIGHT JOIN T1 AS b ON a.rowid = b.rowid;
CREATE  VIEW IF NOT EXISTS v_T1_7732 AS SELECT X FROM T1;
PRAGMA trusted_schema = FALSE;
ANALYZE t1;
SELECT * FROM T2 AS a FULL JOIN T1 AS b ON a.rowid = b.rowid;
ALTER TABLE t1 RENAME TO t1_r4993;
ROLLBACK;
CREATE UNIQUE  INDEX IF NOT EXISTS idx_t1_7121 ON t1((c + 1)) WHERE c IS NOT NULL;
CREATE TABLE T (
  a TEXT,
  b TEXT
);
INSERT INTO T VALUES ('a','b'), ('c','d');
SELECT * FROM T WHERE a = REPLACE('a;',';','') AND b = 'b';
SELECT MIN(Y) FROM T2;
INSERT INTO T1 VALUES ('x', NULL) ON CONFLICT(A) DO UPDATE SET A = excluded.A, X = excluded.X;
REINDEX;
VACUUM;
SELECT * FROM T;
VACUUM;

SELECT COUNT(*) FROM T2;
```

## Actual output

```sql
SQLite version 3.39.0 2022-05-10 23:28:12
Enter ".help" for usage hints.
sqlite> sqlite> sqlite> sqlite> sqlite> sqlite> sqlite> sqlite> sqlite> sqlite> sqlite> CREATE TABLE "t2"("b","c","_ROWID_",PRIMARY KEY("b","c","_ROWID_"))WITHOUT ROWID;
WARNING: writing to an imposter table will corrupt the "t1bc" index!
sqlite> sqlite> Braun|30|3
Wernher||1
von|20|2
sqlite> Braun|30
Wernher|
von|20
sqlite>
```

## Expectation

```sql
SQLite version 3.51.1 2025-11-28 17:28:25
Enter ".help" for usage hints.
sqlite> sqlite> sqlite> sqlite> sqlite> sqlite> sqlite> sqlite> sqlite> sqlite> sqlite> CREATE TABLE "t2"("b","c","_ROWID_",PRIMARY KEY("b","c","_ROWID_"))WITHOUT ROWID;
sqlite> sqlite> Braun|30|3
Wernher||1
von|20|2
sqlite> Braun|30
Wernher|
von|20
sqlite>
```

## Flag

```
-interactive
```

