There are several relationships. In general, as you stop down:
- Less defocus blur (if part of the frame is not within the DOF)
- Same or less lens aberration blur
- More diffraction blur
The optimal F-number for sharpness varies with the lens, camera, and specific circumstances. For example, for one subject, f/16 may be sharper than f/45. But for another subject (that requires more extreme DOF), the f/45 is actually sharper (because it gets the *entire* subject into the DOF instead of just a part of it).
Indirect sharpness relationships include things like motion blur/noise related to stopping down when you cannot keep exposure the same (e.g. low light).