SQLite Forum

"database disk image is malformed" caused by UNION subqueries
Login

"database disk image is malformed" caused by UNION subqueries

(1.1) By Zuming Jiang (zuming_jiang) on 2023-03-19 19:59:42 edited from 1.0 [source]

Set up the database

CREATE TABLE t1 (c6 TEXT collate RTRIM); INSERT INTO t1 VALUES(''); CREATE TABLE t2 (c10 TEXT collate RTRIM); INSERT INTO t2 VALUES(''); CREATE TABLE t3 (c13 TEXT , c14 REAL ); INSERT INTO t3 VALUES('',0.0); INSERT INTO t3 VALUES(NULL,-53.95); INSERT INTO t3 VALUES(NULL,-48.32); INSERT INTO t3 VALUES(NULL,NULL); INSERT INTO t3 VALUES(NULL,64.65); INSERT INTO t3 VALUES(NULL,-79.41); INSERT INTO t3 VALUES(NULL,0.0); INSERT INTO t3 VALUES('sO&0|',11.81); INSERT INTO t3 VALUES('g',NULL); INSERT INTO t3 VALUES(NULL,-52.28); INSERT INTO t3 VALUES(' ',-36.26); INSERT INTO t3 VALUES('+,i;o',0.0); INSERT INTO t3 VALUES('OLs&',0.0); ANALYZE t3;

Test Case to Trigger "database disk image is malformed"

select ref_0.c10 as c23 from t2 as ref_0 where exists ( select distinct ref_2.c6 as c0 from t1 as ref_2 where ((ref_0.c10) = (ref_2.c6)) union select ref_3.c13 as c0 from t3 as ref_3 where ((ref_0.c10) = (ref_3.c13)) and ((ref_3.c14) >= (ref_3.c14)) ); --- Runtime error near line 1: database disk image is malformed (11)

I tested it on the trunk (commit 7d5a549)

(2) By Simon Slavin (slavin) on 2023-03-20 06:25:24 in reply to 1.1 [link] [source]

I had no trouble reproducing this problem in SQLite version 3.39.5 2022-10-14 20:58:05.

Leave out the ANALYZE and it works fine.

(3) By Dan Kennedy (dan) on 2023-03-20 16:12:02 in reply to 1.1 [link] [source]

Thanks for this. It is a bug. Should now be fixed here:

https://sqlite.org/src/info/1b3abc1d

Dan.

(4) By Zuming Jiang (zuming_jiang) on 2023-03-20 16:27:37 in reply to 3 [link] [source]

Thanks for fixing it!