Hi,
After upgrading IDS from 9.21 to 9.40 have you updated the statistics?
If not, to start with, you may use:
update statistics for table;
update statistics for procedure;
To speed up update statistics operation itself, you may fire the SQL which generates a script containing table wise statements.
output to aa without headings select 'update statistics for table '||tabname||';' from systables where tabid>99 ;
Regards,
Shriyan