The difference between Morphine and Codeine is minimal: a H is changed to a CH3. But one is 10x stronger than the other. In fact, morphine is more similar to codeine than to heroin. There is another opioid called Oripavine, similar to morphine (and can be transformed easily into), that is known to also have analgesic effects, but can't be used because it's highly toxic. It can itself be derived to M320, which is around 10000x more potent than morphine. In the opioid large family we could do this all day, with analogs and very similar molecules having a wild range of potency and toxicity.
Don't use similarity between derivatives as a guide or a scale of their potential toxicity. I agree that the easiest and safest way to deal with this is to just legalize all drugs. IMO that will have at least two desirable effects: you will know exactly what you are consuming instead of betting on a derivative, and the race after analogs will stop: people will just consume what is known to be safe and effective, as it happens with alcohol.