SQLite Forum

sqlite3BtreeHoldsMutex: Assertion error
Login
Seems to work with the current version:

```
sqlite> create table x (x);
sqlite> create trigger xx after insert on x begin
   ...> select sin(.5);
   ...> end;
sqlite> insert into x values (1);
sqlite> drop trigger xx;
sqlite> create temporary trigger xx after insert on x begin
   ...> select sin(.5);
   ...> end;
sqlite> insert into x values (1);
sqlite> .eqp full
sqlite> insert into x values (1);
addr  opcode         p1    p2    p3    p4             p5  comment
----  -------------  ----  ----  ----  -------------  --  -------------
0     Init           0     10    0                    0   Start at 10
1     OpenWrite      0     2     0     1              0   root=2 iDb=0; x
2     Integer        1     2     0                    0   r[2]=1
3     NewRowid       0     1     0                    0   r[1]=rowid
4     Noop           0     0     0                    0   BEGIN: GenCnstCks(0,1,1,0,0)
5     MakeRecord     2     1     3                    0   r[3]=mkrec(r[2])
6     Noop           0     0     0                    0   END: GenCnstCks(0)
7     Insert         0     3     1     x              57  intkey=r[1] data=r[3]
8     Program        -1    9     4     program        0   Call: xx.default
9     Halt           0     0     0                    0
10    Transaction    0     1     3     0              1   usesStmtJournal=0
11    Goto           0     1     0                    0
0     Init           0     1     0     -- TRIGGER xx  0   Start at 1; Start: xx.default (AFTER INSERT ON x)
1     Trace          2147483647  1     0     -- select sin(.5)  0
2     Noop           0     0     0                    0   Begin WHERE-core
3     Real           0     2     0     0.5            0   r[2]=0.5
4     Function       1     2     1     sin(1)         0   r[1]=func(r[2])
5     Noop           0     0     0                    0   End WHERE-core
6     Halt           0     0     0                    0   End: xx.default
sqlite> .exit
```

sin(x) is a "custom function" that computes the sine function using the math library.  Going back to the 3.31.1 version seems to work fine too:

```
SQLite version 3.31.1 2020-01-27 21:57:15
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .eqp off
sqlite> create table x(x);
sqlite> create temporary trigger xx after insert on x
   ...> begin
   ...>  select sin(.5);
   ...> end;
sqlite> .eqp full
sqlite> insert into x values (1);
addr  opcode         p1    p2    p3    p4             p5  comment
----  -------------  ----  ----  ----  -------------  --  -------------
0     Init           0     10    0                    00  Start at 10
1     OpenWrite      0     2     0     1              00  root=2 iDb=0; x
2     Integer        1     2     0                    00  r[2]=1
3     NewRowid       0     1     0                    00  r[1]=rowid
4     Noop           0     0     0                    00  BEGIN: GenCnstCks(0,1,1,0,0)
5     MakeRecord     2     1     3                    00  r[3]=mkrec(r[2])
6     Noop           0     0     0                    00  END: GenCnstCks(0)
7     Insert         0     3     1     x              39  intkey=r[1] data=r[3]
8     Program        -1    9     4     program        00  Call: xx.default
9     Halt           0     0     0                    00
10    Transaction    0     1     1     0              01  usesStmtJournal=0
11    Goto           0     1     0                    00
0     Init           0     1     0     -- TRIGGER xx  00  Start at 1; Start: xx.default (AFTER INSERT ON x)
1     Trace          2147483647  1     0     -- select sin(.5)  00
2     Noop           0     0     0                    00  Begin WHERE-core
3     Real           0     2     0     0.5            00  r[2]=0.5
4     Function       1     2     1     sin(1)         00  r[1]=func(r[2])
5     Noop           0     0     0                    00  End WHERE-core
6     Halt           0     0     0                    00  End: xx.default
sqlite>
```

Perhaps it is your function some_function.  If you replace some_function() with a different function (example, datetime) do you get the same result?

```
SQLite version 3.31.1 2020-01-27 21:57:15
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> create table x(x);
sqlite> create temporary trigger xx after insert on x
   ...> begin
   ...>  select datetime();
   ...> end;
sqlite> insert into x values (1);
sqlite> .eqp full
sqlite> insert into x values (2);
addr  opcode         p1    p2    p3    p4             p5  comment
----  -------------  ----  ----  ----  -------------  --  -------------
0     Init           0     10    0                    00  Start at 10
1     OpenWrite      0     2     0     1              00  root=2 iDb=0; x
2     Integer        2     2     0                    00  r[2]=2
3     NewRowid       0     1     0                    00  r[1]=rowid
4     Noop           0     0     0                    00  BEGIN: GenCnstCks(0,1,1,0,0)
5     MakeRecord     2     1     3                    00  r[3]=mkrec(r[2])
6     Noop           0     0     0                    00  END: GenCnstCks(0)
7     Insert         0     3     1     x              39  intkey=r[1] data=r[3]
8     Program        -1    9     4     program        00  Call: xx.default
9     Halt           0     0     0                    00
10    Transaction    0     1     1     0              01  usesStmtJournal=0
11    Goto           0     1     0                    00
0     Init           0     1     0     -- TRIGGER xx  00  Start at 1; Start: xx.default (AFTER INSERT ON x)
1     Trace          2147483647  1     0     -- select datetime()  00
2     Noop           0     0     0                    00  Begin WHERE-core
3     Function       0     0     1     datetime(-1)   00  r[1]=func(r[0])
4     Noop           0     0     0                    00  End WHERE-core
5     Halt           0     0     0                    00  End: xx.default
sqlite> .eqp off
sqlite> select * from x;
1
2
sqlite>
```