## 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);
-- PRAGMA legacy_alter_table = OFF;

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
SAVEPOINT sp9856;
SAVEPOINT sp8755;
ATTACH DATABASE ':memory:' AS aux98;
ATTACH DATABASE ':memory:' AS aux57;
.import corrupt001.db main
BEGIN DEFERRED TRANSACTION;
CREATE TABLE t0(c0);
INSERT INTO t0(c0) VALUES (NULL);
CREATE INDEX i0 ON t0(-(-(json_extract((like('1%', 1, '\\') + 0), '$.key')))) WHERE c0 NOT NULL;
SELECT 1 FROM t0 WHERE (t0.c0 IS FALSE) IS FALSE;
SELECT 1 FROM t0 WHERE (t0.c0 IS FALSE) BETWEEN FALSE OR TRUE;

UPDATE t0 SET c0 = 'x' WHERE c0 BETWEEN 0 AND 100 RETURNING *;
ANALYZE t0;
SELECT * FROM t0 WHERE c0 IN (SELECT c0 FROM t0 ORDER BY c0 LIMIT 1 OFFSET 1000);
END;
ANALYZE;

SELECT * FROM t0 AS a INNER JOIN t0 AS b ON a.rowid = b.rowid;
SELECT * FROM t0;
CREATE TEMP  VIEW IF NOT EXISTS v_t0_2416 AS SELECT c0 FROM t0;

SELECT COUNT(*) FROM t0;
DETACH DATABASE aux57;
VACUUM main;
WITH cte AS (SELECT c0, SUM(c0) OVER (ORDER BY c0) AS running FROM t0) SELECT * FROM cte;
PRAGMA trusted_schema;
CREATE TEMP  VIEW IF NOT EXISTS v_t0_3032 AS SELECT c0 FROM t0;
SELECT LEAD(c0, 2) OVER (ORDER BY c0) FROM t0;
DROP TABLE IF EXISTS t0;
WITH a AS (SELECT * FROM t0), b AS (SELECT * FROM t0) SELECT * FROM a UNION ALL SELECT * FROM b;

SELECT COUNT(*) FROM t0;
SELECT * FROM t0 AS a JOIN t0 AS b ON a.rowid = b.rowid;
ALTER TABLE t0 RENAME TO t0_r7864;
DETACH DATABASE aux98;
ROLLBACK TRANSACTION TO SAVEPOINT sp8755;
RELEASE SAVEPOINT sp8755;
ALTER TABLE t0 ADD COLUMN extra_4590 CHARACTER(20) COLLATE RTRIM;
SAVEPOINT sp8755;
ATTACH DATABASE ':memory:' AS aux98;
ATTACH DATABASE ':memory:' AS aux57;
.import corrupt001.db main
BEGIN DEFERRED TRANSACTION;
CREATE TABLE t0(c0);
INSERT INTO t0(c0) VALUES (NULL);
CREATE INDEX i0 ON t0(-(-(json_extract((like('1%', 1, '\\') + 0), '$.key')))) WHERE c0 NOT NULL;
SELECT 1 FROM t0 WHERE (t0.c0 IS FALSE) IS FALSE;
SELECT 1 FROM t0 WHERE (t0.c0 IS FALSE) BETWEEN FALSE OR TRUE;

UPDATE t0 SET c0 = 'x' WHERE c0 BETWEEN 0 AND 100 RETURNING *;
ANALYZE t0;
SELECT * FROM t0 WHERE c0 IN (SELECT c0 FROM t0 ORDER BY c0 LIMIT 1 OFFSET 1000);
END;
ANALYZE;

SELECT * FROM t0 AS a INNER JOIN t0 AS b ON a.rowid = b.rowid;
SELECT * FROM t0;
CREATE TEMP  VIEW IF NOT EXISTS v_t0_2416 AS SELECT c0 FROM t0;

SELECT COUNT(*) FROM t0;
DETACH DATABASE aux57;
VACUUM main;
WITH cte AS (SELECT c0, SUM(c0) OVER (ORDER BY c0) AS running FROM t0) SELECT * FROM cte;
PRAGMA trusted_schema;
CREATE TEMP  VIEW IF NOT EXISTS v_t0_3032 AS SELECT c0 FROM t0;
SELECT LEAD(c0, 2) OVER (ORDER BY c0) FROM t0;
DROP TABLE IF EXISTS t0;
WITH a AS (SELECT * FROM t0), b AS (SELECT * FROM t0) SELECT * FROM a UNION ALL SELECT * FROM b;

SELECT COUNT(*) FROM t0;
SELECT * FROM t0 AS a JOIN t0 AS b ON a.rowid = b.rowid;
ALTER TABLE t0 RENAME TO t0_r7864;
DETACH DATABASE aux98;
ROLLBACK TRANSACTION TO SAVEPOINT sp8755;
RELEASE SAVEPOINT sp8755;
ALTER TABLE t0 ADD COLUMN extra_4590 CHARACTER(20) COLLATE RTRIM;
SAVEPOINT sp8755;
ATTACH DATABASE ':memory:' AS aux98;
ATTACH DATABASE ':memory:' AS aux57;
.import corrupt001.db main
BEGIN DEFERRED TRANSACTION;
CREATE TABLE t0(c0);
INSERT INTO t0(c0) VALUES (NULL);
CREATE INDEX i0 ON t0(-(-(json_extract((like('1%', 1, '\\') + 0), '$.key')))) WHERE c0 NOT NULL;
SELECT 1 FROM t0 WHERE (t0.c0 IS FALSE) IS FALSE;
SELECT 1 FROM t0 WHERE (t0.c0 IS FALSE) BETWEEN FALSE OR TRUE;

UPDATE t0 SET c0 = 'x' WHERE c0 BETWEEN 0 AND 100 RETURNING *;
ANALYZE t0;
SELECT * FROM t0 WHERE c0 IN (SELECT c0 FROM t0 ORDER BY c0 LIMIT 1 OFFSET 1000);
END;
ANALYZE;

SELECT * FROM t0 AS a INNER JOIN t0 AS b ON a.rowid = b.rowid;
SELECT * FROM t0;
CREATE TEMP  VIEW IF NOT EXISTS v_t0_2416 AS SELECT c0 FROM t0;

SELECT COUNT(*) FROM t0;
DETACH DATABASE aux57;
VACUUM main;
WITH cte AS (SELECT c0, SUM(c0) OVER (ORDER BY c0) AS running FROM t0) SELECT * FROM cte;
PRAGMA trusted_schema;
CREATE TEMP  VIEW IF NOT EXISTS v_t0_3032 AS SELECT c0 FROM t0;
SELECT LEAD(c0, 2) OVER (ORDER BY c0) FROM t0;
DROP TABLE IF EXISTS t0;
WITH a AS (SELECT * FROM t0), b AS (SELECT * FROM t0) SELECT * FROM a UNION ALL SELECT * FROM b;

SELECT COUNT(*) FROM t0;
SELECT * FROM t0 AS a JOIN t0 AS b ON a.rowid = b.rowid;
ALTER TABLE t0 RENAME TO t0_r7864;
DETACH DATABASE aux98;
ROLLBACK TRANSACTION TO SAVEPOINT sp8755;
RELEASE SAVEPOINT sp8755;
ALTER TABLE t0 ADD COLUMN extra_4590 CHARACTER(20) COLLATE RTRIM;
SAVEPOINT sp8755;
ATTACH DATABASE ':memory:' AS aux98;
ATTACH DATABASE ':memory:' AS aux57;
.import corrupt001.db main
BEGIN DEFERRED TRANSACTION;
CREATE TABLE t0(c0);
INSERT INTO t0(c0) VALUES (NULL);
CREATE INDEX i0 ON t0(-(-(json_extract((like('1%', 1, '\\') + 0), '$.key')))) WHERE c0 NOT NULL;
SELECT 1 FROM t0 WHERE (t0.c0 IS FALSE) IS FALSE;
SELECT 1 FROM t0 WHERE (t0.c0 IS FALSE) BETWEEN FALSE OR TRUE;

UPDATE t0 SET c0 = 'x' WHERE c0 BETWEEN 0 AND 100 RETURNING *;
ANALYZE t0;
SELECT * FROM t0 WHERE c0 IN (SELECT c0 FROM t0 ORDER BY c0 LIMIT 1 OFFSET 1000);
END;
ANALYZE;

SELECT * FROM t0 AS a INNER JOIN t0 AS b ON a.rowid = b.rowid;
SELECT * FROM t0;
CREATE TEMP  VIEW IF NOT EXISTS v_t0_2416 AS SELECT c0 FROM t0;

SELECT COUNT(*) FROM t0;
DETACH DATABASE aux57;
VACUUM main;
WITH cte AS (SELECT c0, SUM(c0) OVER (ORDER BY c0) AS running FROM t0) SELECT * FROM cte;
PRAGMA trusted_schema;
CREATE TEMP  VIEW IF NOT EXISTS v_t0_3032 AS SELECT c0 FROM t0;
SELECT LEAD(c0, 2) OVER (ORDER BY c0) FROM t0;
DROP TABLE IF EXISTS t0;
WITH a AS (SELECT * FROM t0), b AS (SELECT * FROM t0) SELECT * FROM a UNION ALL SELECT * FROM b;

SELECT COUNT(*) FROM t0;
SELECT * FROM t0 AS a JOIN t0 AS b ON a.rowid = b.rowid;
ALTER TABLE t0 RENAME TO t0_r7864;
DETACH DATABASE aux98;
ROLLBACK TRANSACTION TO SAVEPOINT sp8755;
RELEASE SAVEPOINT sp8755;
ALTER TABLE t0 ADD COLUMN extra_4590 CHARACTER(20) COLLATE RTRIM;
SAVEPOINT sp8755;
ATTACH DATABASE ':memory:' AS aux98;
ATTACH DATABASE ':memory:' AS aux57;
.import corrupt001.db main
BEGIN DEFERRED TRANSACTION;
CREATE TABLE t0(c0);
INSERT INTO t0(c0) VALUES (NULL);
CREATE INDEX i0 ON t0(-(-(json_extract((like('1%', 1, '\\') + 0), '$.key')))) WHERE c0 NOT NULL;
SELECT 1 FROM t0 WHERE (t0.c0 IS FALSE) IS FALSE;
SELECT 1 FROM t0 WHERE (t0.c0 IS FALSE) BETWEEN FALSE OR TRUE;

UPDATE t0 SET c0 = 'x' WHERE c0 BETWEEN 0 AND 100 RETURNING *;
ANALYZE t0;
SELECT * FROM t0 WHERE c0 IN (SELECT c0 FROM t0 ORDER BY c0 LIMIT 1 OFFSET 1000);
END;
ANALYZE;

SELECT * FROM t0 AS a INNER JOIN t0 AS b ON a.rowid = b.rowid;
SELECT * FROM t0;
CREATE TEMP  VIEW IF NOT EXISTS v_t0_2416 AS SELECT c0 FROM t0;

SELECT COUNT(*) FROM t0;
DETACH DATABASE aux57;
VACUUM main;
WITH cte AS (SELECT c0, SUM(c0) OVER (ORDER BY c0) AS running FROM t0) SELECT * FROM cte;
PRAGMA trusted_schema;
CREATE TEMP  VIEW IF NOT EXISTS v_t0_3032 AS SELECT c0 FROM t0;
SELECT LEAD(c0, 2) OVER (ORDER BY c0) FROM t0;
DROP TABLE IF EXISTS t0;
WITH a AS (SELECT * FROM t0), b AS (SELECT * FROM t0) SELECT * FROM a UNION ALL SELECT * FROM b;

SELECT COUNT(*) FROM t0;
SELECT * FROM t0 AS a JOIN t0 AS b ON a.rowid = b.rowid;
ALTER TABLE t0 RENAME TO t0_r7864;
DETACH DATABASE aux98;
ROLLBACK TRANSACTION TO SAVEPOINT sp8755;
RELEASE SAVEPOINT sp8755;
ALTER TABLE t0 ADD COLUMN extra_4590 CHARACTER(20) COLLATE RTRIM;
SAVEPOINT sp8755;
ATTACH DATABASE ':memory:' AS aux98;
ATTACH DATABASE ':memory:' AS aux57;
.import corrupt001.db main
BEGIN DEFERRED TRANSACTION;
CREATE TABLE t0(c0);
INSERT INTO t0(c0) VALUES (NULL);
CREATE INDEX i0 ON t0(-(-(json_extract((like('1%', 1, '\\') + 0), '$.key')))) WHERE c0 NOT NULL;
SELECT 1 FROM t0 WHERE (t0.c0 IS FALSE) IS FALSE;
SELECT 1 FROM t0 WHERE (t0.c0 IS FALSE) BETWEEN FALSE OR TRUE;

UPDATE t0 SET c0 = 'x' WHERE c0 BETWEEN 0 AND 100 RETURNING *;
ANALYZE t0;
SELECT * FROM t0 WHERE c0 IN (SELECT c0 FROM t0 ORDER BY c0 LIMIT 1 OFFSET 1000);
END;
ANALYZE;

SELECT * FROM t0 AS a INNER JOIN t0 AS b ON a.rowid = b.rowid;
SELECT * FROM t0;
CREATE TEMP  VIEW IF NOT EXISTS v_t0_2416 AS SELECT c0 FROM t0;

SELECT COUNT(*) FROM t0;
DETACH DATABASE aux57;
VACUUM main;
WITH cte AS (SELECT c0, SUM(c0) OVER (ORDER BY c0) AS running FROM t0) SELECT * FROM cte;
PRAGMA trusted_schema;
CREATE TEMP  VIEW IF NOT EXISTS v_t0_3032 AS SELECT c0 FROM t0;
SELECT LEAD(c0, 2) OVER (ORDER BY c0) FROM t0;
DROP TABLE IF EXISTS t0;
WITH a AS (SELECT * FROM t0), b AS (SELECT * FROM t0) SELECT * FROM a UNION ALL SELECT * FROM b;

SELECT COUNT(*) FROM t0;
SELECT * FROM t0 AS a JOIN t0 AS b ON a.rowid = b.rowid;
ALTER TABLE t0 RENAME TO t0_r7864;
DETACH DATABASE aux98;
ROLLBACK TRANSACTION TO SAVEPOINT sp8755;
RELEASE SAVEPOINT sp8755;
ALTER TABLE t0 ADD COLUMN extra_4590 CHARACTER(20) COLLATE RTRIM;
SAVEPOINT sp8755;
ATTACH DATABASE ':memory:' AS aux98;
ATTACH DATABASE ':memory:' AS aux57;
.import corrupt001.db main
BEGIN DEFERRED TRANSACTION;
CREATE TABLE t0(c0);
INSERT INTO t0(c0) VALUES (NULL);
CREATE INDEX i0 ON t0(-(-(json_extract((like('1%', 1, '\\') + 0), '$.key')))) WHERE c0 NOT NULL;
SELECT 1 FROM t0 WHERE (t0.c0 IS FALSE) IS FALSE;
SELECT 1 FROM t0 WHERE (t0.c0 IS FALSE) BETWEEN FALSE OR TRUE;

UPDATE t0 SET c0 = 'x' WHERE c0 BETWEEN 0 AND 100 RETURNING *;
ANALYZE t0;
SELECT * FROM t0 WHERE c0 IN (SELECT c0 FROM t0 ORDER BY c0 LIMIT 1 OFFSET 1000);
END;
ANALYZE;

SELECT * FROM t0 AS a INNER JOIN t0 AS b ON a.rowid = b.rowid;
SELECT * FROM t0;
CREATE TEMP  VIEW IF NOT EXISTS v_t0_2416 AS SELECT c0 FROM t0;

SELECT COUNT(*) FROM t0;
DETACH DATABASE aux57;
VACUUM main;
WITH cte AS (SELECT c0, SUM(c0) OVER (ORDER BY c0) AS running FROM t0) SELECT * FROM cte;
PRAGMA trusted_schema;
CREATE TEMP  VIEW IF NOT EXISTS v_t0_3032 AS SELECT c0 FROM t0;
SELECT LEAD(c0, 2) OVER (ORDER BY c0) FROM t0;
DROP TABLE IF EXISTS t0;
WITH a AS (SELECT * FROM t0), b AS (SELECT * FROM t0) SELECT * FROM a UNION ALL SELECT * FROM b;

SELECT COUNT(*) FROM t0;
SELECT * FROM t0 AS a JOIN t0 AS b ON a.rowid = b.rowid;
ALTER TABLE t0 RENAME TO t0_r7864;
DETACH DATABASE aux98;
ROLLBACK TRANSACTION TO SAVEPOINT sp8755;
RELEASE SAVEPOINT sp8755;
ALTER TABLE t0 ADD COLUMN extra_4590 CHARACTER(20) COLLATE RTRIM;
SAVEPOINT sp8755;
ATTACH DATABASE ':memory:' AS aux98;
ATTACH DATABASE ':memory:' AS aux57;
.import corrupt001.db main
BEGIN DEFERRED TRANSACTION;
CREATE TABLE t0(c0);
INSERT INTO t0(c0) VALUES (NULL);
CREATE INDEX i0 ON t0(-(-(json_extract((like('1%', 1, '\\') + 0), '$.key')))) WHERE c0 NOT NULL;
SELECT 1 FROM t0 WHERE (t0.c0 IS FALSE) IS FALSE;
SELECT 1 FROM t0 WHERE (t0.c0 IS FALSE) BETWEEN FALSE OR TRUE;

UPDATE t0 SET c0 = 'x' WHERE c0 BETWEEN 0 AND 100 RETURNING *;
ANALYZE t0;
SELECT * FROM t0 WHERE c0 IN (SELECT c0 FROM t0 ORDER BY c0 LIMIT 1 OFFSET 1000);
END;
ANALYZE;

SELECT * FROM t0 AS a INNER JOIN t0 AS b ON a.rowid = b.rowid;
SELECT * FROM t0;
CREATE TEMP  VIEW IF NOT EXISTS v_t0_2416 AS SELECT c0 FROM t0;

SELECT COUNT(*) FROM t0;
DETACH DATABASE aux57;
VACUUM main;
WITH cte AS (SELECT c0, SUM(c0) OVER (ORDER BY c0) AS running FROM t0) SELECT * FROM cte;
PRAGMA trusted_schema;
CREATE TEMP  VIEW IF NOT EXISTS v_t0_3032 AS SELECT c0 FROM t0;
SELECT LEAD(c0, 2) OVER (ORDER BY c0) FROM t0;
DROP TABLE IF EXISTS t0;
WITH a AS (SELECT * FROM t0), b AS (SELECT * FROM t0) SELECT * FROM a UNION ALL SELECT * FROM b;

SELECT COUNT(*) FROM t0;
SELECT * FROM t0 AS a JOIN t0 AS b ON a.rowid = b.rowid;
ALTER TABLE t0 RENAME TO t0_r7864;
DETACH DATABASE aux98;
ROLLBACK TRANSACTION TO SAVEPOINT sp8755;
RELEASE SAVEPOINT sp8755;
ALTER TABLE t0 ADD COLUMN extra_4590 CHARACTER(20) COLLATE RTRIM;
SAVEPOINT sp8755;
ATTACH DATABASE ':memory:' AS aux98;
ATTACH DATABASE ':memory:' AS aux57;
.import corrupt001.db main
BEGIN DEFERRED TRANSACTION;
CREATE TABLE t0(c0);
INSERT INTO t0(c0) VALUES (NULL);
CREATE INDEX i0 ON t0(-(-(json_extract((like('1%', 1, '\\') + 0), '$.key')))) WHERE c0 NOT NULL;
SELECT 1 FROM t0 WHERE (t0.c0 IS FALSE) IS FALSE;
SELECT 1 FROM t0 WHERE (t0.c0 IS FALSE) BETWEEN FALSE OR TRUE;

UPDATE t0 SET c0 = 'x' WHERE c0 BETWEEN 0 AND 100 RETURNING *;
ANALYZE t0;
SELECT * FROM t0 WHERE c0 IN (SELECT c0 FROM t0 ORDER BY c0 LIMIT 1 OFFSET 1000);
END;
ANALYZE;

SELECT * FROM t0 AS a INNER JOIN t0 AS b ON a.rowid = b.rowid;
SELECT * FROM t0;
CREATE TEMP  VIEW IF NOT EXISTS v_t0_2416 AS SELECT c0 FROM t0;

SELECT COUNT(*) FROM t0;
DETACH DATABASE aux57;
VACUUM main;
WITH cte AS (SELECT c0, SUM(c0) OVER (ORDER BY c0) AS running FROM t0) SELECT * FROM cte;
PRAGMA trusted_schema;
CREATE TEMP  VIEW IF NOT EXISTS v_t0_3032 AS SELECT c0 FROM t0;
SELECT LEAD(c0, 2) OVER (ORDER BY c0) FROM t0;
DROP TABLE IF EXISTS t0;
WITH a AS (SELECT * FROM t0), b AS (SELECT * FROM t0) SELECT * FROM a UNION ALL SELECT * FROM b;

SELECT COUNT(*) FROM t0;
SELECT * FROM t0 AS a JOIN t0 AS b ON a.rowid = b.rowid;
ALTER TABLE t0 RENAME TO t0_r7864;
DETACH DATABASE aux98;
ROLLBACK TRANSACTION TO SAVEPOINT sp8755;
RELEASE SAVEPOINT sp8755;
ALTER TABLE t0 ADD COLUMN extra_4590 CHARACTER(20) COLLATE RTRIM;

INSERT INTO t0 VALUES (NULL) ON CONFLICT(c0) DO UPDATE SET c0 = excluded.c0;
ALTER TABLE t0 RENAME COLUMN c0 TO c0_r3992;
RELEASE sp9856;
```

## 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

```

```

