subtype missed under index
(1) By ChiZhang on 2026-05-15 11:48:49 [source]
Hi,
I found that the subtype of JSON will be lost when the query uses an index.
This test case can reproduce this:
CREATE TABLE t(a INTEGER, j TEXT);
INSERT INTO t VALUES(1,'{"a":1}'),(2,'{"a":2}');
CREATE INDEX i_case ON t(CASE WHEN a>0 THEN json(j) END);
SELECT subtype(CASE WHEN a>0 THEN json(j) END) FROM t NOT INDEXED WHERE a=2;
SELECT subtype(CASE WHEN a>0 THEN json(j) END) FROM t INDEXED BY i_case WHERE a=2;
This is the output:
╭──────────────────────╮
│ subtype(CASE WHEN... │
╞══════════════════════╡
│ 74 │
╰──────────────────────╯
╭──────────────────────╮
│ subtype(CASE WHEN... │
╞══════════════════════╡
│ 0 │
╰──────────────────────╯
I can reproduce this with the trunk version 83d3a0d39b.