A good bike shop keeps all -- or almost all -- of its old parts. These can be used for the "wizard jobs" in which experienced, talented mechanics can improvise, substitute or re-engineer components to fix them quickly, without having to expend the time and money to order complete new assemblies.
A great bike shop actually sorts and catalogs the old parts. Perhaps they even offer them for sale, along with new old stock and other stashes of retro treasure. See Harris Cyclery for an example. And we did it at the first shop I worked for. In the slow months of late fall and winter, we had time to dig in the crypts of the shop basement and set up the used parts area. One of us also reconditioned a number of used bikes with those parts, to use for rentals.
Fixing bikes is a lot like the cable television show Junkyard Wars, in which teams compete to make usable mechanisms out of whatever they find lying around. Depending on how well equipped the shop is, the bike mechanic starts with some advantage, knowing certain items will be there. But with all the variety in bike parts over the years, we often come up against a challenge that calls for more ingenuity than simply going to the pristine parts shelf and picking out the exact item in a sealed package.