You can prepare a statement and then execute it:
set @sql = concat('select * from table1 where tag in (', ids, ')');
PREPARE q FROM @sql;
execute q;
This constructs the string for each execution, so you can use in
. The resulting execute should be able to use an index on tag
, which should speed things up considerably.