As mentioned, there's no sensor or switch in the car that says "ooh, he just gave it the good stuff, we got 250HP now"
The power adjustment is mainly a result of timing adjustments. With higher octane fuel, the engine can run more aggressive timing without knocking. Knocking is very bad so this sensor talks to the computer and the computer lets the engine push it as far as it can go without damaging itself. If the knock sensor says everything is good it will throw timing at it until it gets to the point where it says "whoah, that's all we can do" and it stops. As computing power has increased car computers are quicker than they used to be and if the tuning and programming has been put into the car the computers can change the engine tune to make better use of available qualities of fuel. This allows the driver to decide what they want or need out of the engine by what they put into the tank.
Where traditional vehicles are rated for 1 recommended AKI rating, anything above that is a waste as the computer isn't capable of adjusting the engine's performance to take advantage of the additional capabilities of the fuel itself. The engine will just see everything is good and let it run at it's low octane tune even if high octane is in it.
They told me the O2 sensors detect octane levels.
That sounds bunk to me, but that's what Mazda told me when I called Mazda corporate.
There are typically 2 x 02 sensors (minimum) in cars these days: a front one and a rear one. There may be a set of these on each bank if you're running a V or H configuration engine, one pair for left bank and one pair for right bank. Typically only 1 pair for an inline engine.
The front O2 sensor is the one that helps control the engine. It measures the gases exiting the combustion chamber
before it hits the catalytic converter. The measured gas mixture tells the computer the air / fuel mixture ratio: it tells the computer if the car is running lean, rich, or optimal. If it's lean it gives the engine more fuel to bring the mixture to optimal. If it's rich it will pull fuel to bring the mixture down to optimal. It doesn't sense the fuel type.
To keep it simple, the knock sensor controls spark timing and the O2 sensor controls the air/fuel mixture. The cam and crank position sensors tells the computer if the valves and crank shaft are in the correct positions in relation to each other to accept a spark / combustion. If the valves and pistons aren't in the right spot the computer will cut the spark or fuel to avoid the engine damaging itself.
The rear O2 sensor typically doesn't control the engine. It simply measures the exhaust gases
after the catalytic converter and compared them to the readings from the 1st O2 sensor to ensure that your catalytic converter is doing it's job