With “normal sized” prints from 35mm film cameras, I think it was fairly well-known that at about f/22 or a bit beyond, images start to get a bit soft, moving towards the pin-hole camera effect as you stop down further: that’s diffraction. For those of us who still display and view images in “normal” fashion, from not closer than the long dimension of the image, diffraction continues to be a visible factor only at or beyond the smallest apertures that cameras offer. But likewise, such display/viewing style does not benefit in visible sharpness from going beyond about 12MP—maybe 24MP as a generous estimate.
This discussion of diffraction is therefore mostly relevant to those who are using the newer higher resolution cameras and want to make good use of the extra sensor resolution: “big prints viewed up close” so that only a part of the scene is being seen at a time, rather than “holistic” viewing.
For this case, I suggest a simple procedure. First find at what apertures you see significant “pinhole softening” in normal viewing, for which about 6-12MP gives all the needed sharpness. Then for each doubling of pixel count—and thus doubling of print area if you aim at the same viewing distance and print PPI—reduce that “pinhole softening threshold” one stop. If however that gives too little DOF so that improving sharpness of the in-focus subjects causes unacceptable loss of sharpness elsewhere in the image, stay with the smaller aperture—and accept that the latest upgrade of your pixel count is of no value for this particular composition. If that happens most or all of the time, congratulations: the MP race is over for you! (As it is for me and my style of photography.)
One catch though: each doubling of pixel count and intended print size (with equal viewing distance) makes that OOF blurring more visible, so not only might you want not to open up one stop to keep the main subject fully sharp; you might actually want to stop down to protect other parts of the scene from too much OOF softening. Which means that the maximum worthwhile pixel count—and maximum print size at which everything you want sharp does like look sharp—is even more limited by the closing twin jaws of diffraction and OOF effects.
Maybe focus stacking is a partial way out; e. g. several diffraction-free images at f/5.6 or f/8 rather than the f/11 or f/16 that your DOF needs dictates.