>Does the query optimizer coalesce identical calls to deterministic functions?

It’s not coalesce identical calls when inserting new record.

CREATE TABLE t(x json);
CREATE INDEX i2 on t(json_extract(x,'$.type')) where json_extract(x,'$.type') 
not null;
explain insert into t values(?);

addr  opcode         p1    p2    p3    p4             p5  comment
----  -------------  ----  ----  ----  -------------  --  -------------
0     Init           0     21    0                    00  Start at 21
1     OpenWrite      0     2     0     1              00  root=2 iDb=0; t
2     OpenWrite      1     4     0     k(2,,)         00  root=4 iDb=0; i2
3     NewRowid       0     1     0                    00  r[1]=rowid
4     Variable       1     2     0                    00  r[2]=parameter(1,)
5     Affinity       2     1     0     C              00  affinity(r[2])
6     Null           0     3     0                    00  r[3]=NULL
7     Copy           2     5     0                    00  r[5]=r[2]
8     Function0      2     5     4     json_extract(-1)  02  r[4]=func(r[5..6])
9     IsNull         4     14    0                    00  if r[4]==NULL goto 14
10    Copy           2     9     0                    00  r[9]=r[2]
11    Function0      2     9     7     json_extract(-1)  02  
r[7]=func(r[9..10]); i2 column 0
12    IntCopy        1     8     0                    00  r[8]=r[1]; rowid
13    MakeRecord     7     2     3                    00  r[3]=mkrec(r[7..8]); 
for i2
14    IsNull         3     16    0                    00  if r[3]==NULL goto 16
15    IdxInsert      1     3     0                    10  key=r[3]
16    MakeRecord     2     1     4                    00  r[4]=mkrec(r[2])
17    Insert         0     4     1     t              1b  intkey=r[1] data=r[4]
18    Close          0     0     0                    00
19    Close          1     0     0                    00
20    Halt           0     0     0                    00
21    Transaction    0     1     5     0              01  usesStmtJournal=0
22    TableLock      0     2     1     t              00  iDb=0 root=2 write=1
23    String8        0     6     0     $.type         00  r[6]='$.type'
24    String8        0     10    0     $.type         00  r[10]='$.type'
25    Goto           0     1     0                    00

_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to