Octane is just a measure of knock resistance - there are many other properties that are different between fuels - energy density, heat of vaporization, specific heat and “oxygenation”, etc.
The “pump gas” you get actually varies a lot in terms of the hydrocarbon content, blends, seasons, etc, but because of tight regulations on certain properties (not just octane) your engine will usually operate safely but things like gas mileage (energy content) will vary.
But once you deviate from gasoline to high ethanol blends, methanol, nitromethane, etc, the fuels are as different as diesel and gasoline, maybe moreso. Air fuel ratios are completely different because the above fuels all contain some of their own oxygen, so less air is required to burn. Or alternately, since airflow is the limiting factor, you can run more fuel and make more power off the same amount of air. You also kind of have to run more fuel in order to stay in the range of flammability.
The tuning approaches of “race gas” and ethanol are also slightly different - high octane race gas just lets you gain power by advancing timing closer to the “ideal” point where peak cylinder pressure can be reached without running into detonation. Ethanol also lets you run more timing by virtue of high octane rating, but because it’s oxygenated, you can dump more fuel in. Even though ethanol is less energy dense (and so results in lower gas mileage), the additional fuel means more total energy release, and more power.
In other words, E40, which is ~98 octane will, if properly tuned with the extra fuel flow required be capable of higher power output than similar 100 octane race gas, because there’s more total hydrogen, carbon and oxygen flowing through the engine when given the same inlet airflow, in exactly the same way that a nitrous fogger with additional fuel would
This is taken to an extreme in top fuel and nitromethane burning dragster/funny car engines, where instead of the 14.7:1 air-fuel ratio of gasoline, because of the extra free oxygen, you get AFRs:
Ethanol: 9.0:1
Methanol: 6.5:1
Nitromethane: 1.7:1
Other words, nitromethane is a large part of the way to dumping massive quantities of rocket fuel containing its own oxidizer into your engine, supplemented by additional air.
As long as you are just dealing with gasoline equivalent blends of various 6-8 chain hydrocarbons, octane rating is the primary limiting factor in approaching ideal peak cylinder pressure, but once you throw oxygenated fuels into the mix, or fuels that require a drastically different AFR (like propane or hydrogen), you are no longer looking at the same thing.
Ultimately, your engine power is limited by how much air you can stuff into it, and then by the quantity of fuel you can burn with that air, unless you run into a volumetric limitation on fueling, a knock threshold that prevents reaching peak cylinder pressure or a mechanical strength limitation because you bend a con-rod. Which is how 80’s formula one cars managed as high as 1400hp out of the 1.5 liter displacement - more air (by running 50-80 psi boost) and more fuel