I stumbled over this while running some JUnit tests of our Applications which uses the embedded version of BaseX. It always seemed to happen when inserting, deleting and then inserting the same documents again. I attached 4 simple xquery files to reproduce it using basexgui, just follow these steps:
1. open basexgui
2. create an empty database
3. run insert_pigs.xq to insert the first document
4. run insert_plants.xq to insert the second document
5. run delete_pigs.xq to delete the first document
6. run delete_plants.xq to delete the second document
now insert the same 2 documents in the opposite order
7: run insert_pigs.xq
8. run insert_plants.xq <-- this will trigger the error, the database is now garbage
Some more observations:
It does not trigger when using only 1 document. Not sure if it happens with more than 2, I think I have observed that as well. Sometimes closing the database and running optimize on it seems to fix it.
Hope that helps to find and fiy the bug, its pretty nasty.
BR
Herbert