The Query execution plan is quite different I noticed:
First Query: Result: element { "smiles" } { for $i in IndexAccess("298038", ATV)/self::*:id/parent::*:molecule/*:identifier[@*:convention = "iupac:smile"] return element { "smile" } { $i/@value } }
Second Query: Result: for $i in IndexAccess("iupac:smile", ATV)/self::*:convention/parent::*:identifier[parent::*:molecule[@*:id = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)]] return element { "smile" } { $i/@value }
Query optimizer tries to find the cheapest index evaluation. As the costs for queries on variables cannot be estimated in advance, the optimizer will choose the index access for "iupac:simple". If you want to enforce index access on a certain expression, you could try to rewrite your query, so that the other expressions cannot be optimized.
Next, the optimizer prefers single string values (although range queries are generally supported as well). In your query, it might help to first convert your ids to strings, such as shown here:
let $ids := for $i in 1 to 10 return string($i) for $i in //*:molecule[@*:id = $ids]/*:identifier[@*:convention="iupac:smile"] return $i
Hope this helps, Christian