Under some circumstances, the dbid of a temporary object is remapped to the temporary database ID of the current session to ensure that these objects are created and accessed in the correct temporary database. For example:
When a stored procedure is created by a session that is attached to one temporary database, and then is compiled by another session in a different temporary database.
When a stored procedure is compiled by a session that is different than the temporary database of the session executing it.
However, remapping temporary database IDs does not ensure that the procedure behaves identically across temporary databases. A procedure compiled in one temporary database with certain caching characteristics may perform very differently when run in a temporary database with a different set of caching characteristics. Similarly, a procedure compiled in one temporary database with certain dboption settings may have very different semantics when executed in a temporary database with different dboptions settings.