Hi Alex,
thanks for the reproducible test files. It seems your main loop returns many duplicates. The attached query should be processed much faster (on my machine, it's processed in 500ms). I didn't work with updindex=true, though.
$ ./basex -Vc"SET ATTRINDEX true;SET UPDINDEX true;CREATE DB test2" # loop, adding documents
Assuming that all imported files are located in a local directory.. Did you try to add all documents in one go?
basex -Vc"CREATE DB test2 /path/to/back"
$ ./basex -Vc"OPEN test2;CREATE INDEX ATTRIBUTE;OPTIMIZE"
By the way, there is no need to create the attribute index, as this will be automatically done by optimize. You could as well try to run "optimize all", which will rebuild the "updindex" data structures.
Christian