One of my favorite tricks for this is in ORMs that let you "select related" -- they'll work out what objects you explicitly asked for, and if you tell them do "select related" they'll also figure out what other objects (through foreign keys or intermediary many-to-many tables) are related to them, and fetch the whole batch in the same connection.
Of course, this is more of a performance tradeoff (because it means more objects in memory) than a pure performance enhancement, but for many common cases it's a worthwhile tradeoff to make.
↧